JsonParameterInfo<T>
Represents a strongly-typed parameter to prevent boxing where have less than 4 parameters.
Holds relevant state like the default value of the parameter, and the position in the method's parameter list.
namespace System.Text.Json.Serialization.Metadata
{
internal sealed class JsonParameterInfo<T> : JsonParameterInfo
{
public T TypedDefaultValue { get; set; }
public override void Initialize(JsonParameterInfoValues parameterInfo, JsonPropertyInfo matchingProperty, JsonSerializerOptions options)
{
base.Initialize(parameterInfo, matchingProperty, options);
InitializeDefaultValue(matchingProperty);
}
private void InitializeDefaultValue(JsonPropertyInfo matchingProperty)
{
if (ClrInfo.HasDefaultValue) {
object defaultValue = ClrInfo.DefaultValue;
if (defaultValue == null && !matchingProperty.PropertyTypeCanBeNull)
base.DefaultValue = TypedDefaultValue;
else {
base.DefaultValue = defaultValue;
TypedDefaultValue = (T)defaultValue;
}
} else
base.DefaultValue = TypedDefaultValue;
}
}
}