From f8b5f7ff5ab145f7b69d15f401c20e0bf4642431 Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Tue, 30 Jul 2024 08:35:15 +0200 Subject: [PATCH] Allow setting parameter content type --- src/RestSharp/Parameters/Parameter.cs | 37 ++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/RestSharp/Parameters/Parameter.cs b/src/RestSharp/Parameters/Parameter.cs index 903b33402..b23c592dc 100644 --- a/src/RestSharp/Parameters/Parameter.cs +++ b/src/RestSharp/Parameters/Parameter.cs @@ -32,13 +32,29 @@ protected Parameter(string? name, object? value, ParameterType type, bool encode } /// - /// MIME content type of the parameter + /// Content type of the parameter. Normally applies to the body parameter, or POST parameter in multipart requests. /// - public ContentType ContentType { get; protected init; } = ContentType.Undefined; - public string? Name { get; } - public object? Value { get; } - public ParameterType Type { get; } - public bool Encode { get; } + public ContentType ContentType { get; set; } = ContentType.Undefined; + + /// + /// Parameter name + /// + public string? Name { get; } + + /// + /// Parameter value + /// + public object? Value { get; } + + /// + /// Parameter type + /// + public ParameterType Type { get; } + + /// + /// Indicates if the parameter value should be encoded or not. + /// + public bool Encode { get; } /// /// Return a human-readable representation of this parameter @@ -48,6 +64,15 @@ protected Parameter(string? name, object? value, ParameterType type, bool encode protected virtual string ValueString => Value?.ToString() ?? "null"; + /// + /// Creates a parameter object of based on the type + /// + /// Parameter name + /// Parameter value + /// Parameter type + /// Indicates if the parameter value should be encoded + /// + /// public static Parameter CreateParameter(string? name, object? value, ParameterType type, bool encode = true) // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault => type switch {