Skip to content

Commit

Permalink
Allow setting parameter content type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Jul 30, 2024
1 parent 4ddda24 commit f8b5f7f
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/RestSharp/Parameters/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,29 @@ protected Parameter(string? name, object? value, ParameterType type, bool encode
}

/// <summary>
/// MIME content type of the parameter
/// Content type of the parameter. Normally applies to the body parameter, or POST parameter in multipart requests.
/// </summary>
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;

/// <summary>
/// Parameter name
/// </summary>
public string? Name { get; }

/// <summary>
/// Parameter value
/// </summary>
public object? Value { get; }

/// <summary>
/// Parameter type
/// </summary>
public ParameterType Type { get; }

/// <summary>
/// Indicates if the parameter value should be encoded or not.
/// </summary>
public bool Encode { get; }

/// <summary>
/// Return a human-readable representation of this parameter
Expand All @@ -48,6 +64,15 @@ protected Parameter(string? name, object? value, ParameterType type, bool encode

protected virtual string ValueString => Value?.ToString() ?? "null";

/// <summary>
/// Creates a parameter object of based on the type
/// </summary>
/// <param name="name">Parameter name</param>
/// <param name="value">Parameter value</param>
/// <param name="type">Parameter type</param>
/// <param name="encode">Indicates if the parameter value should be encoded</param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static Parameter CreateParameter(string? name, object? value, ParameterType type, bool encode = true)
// ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
=> type switch {
Expand Down

0 comments on commit f8b5f7f

Please sign in to comment.