JsonParameterInfo
Provides JSON serialization-related metadata about a constructor parameter.
using System.Reflection;
using System.Runtime.CompilerServices;
namespace System.Text.Json.Serialization.Metadata
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class JsonParameterInfo
{
private ICustomAttributeProvider _attributeProvider;
public Type DeclaringType => MatchingProperty.DeclaringType;
public int Position { get; }
public Type ParameterType => MatchingProperty.PropertyType;
public string Name { get; }
public bool HasDefaultValue { get; }
[System.Runtime.CompilerServices.Nullable(2)]
public object DefaultValue {
[System.Runtime.CompilerServices.NullableContext(2)]
get;
}
[System.Runtime.CompilerServices.Nullable(2)]
internal object EffectiveDefaultValue { get; set; }
public bool IsNullable => MatchingProperty.IsSetNullable;
public bool IsMemberInitializer { get; }
[System.Runtime.CompilerServices.Nullable(2)]
public ICustomAttributeProvider AttributeProvider {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
ICustomAttributeProvider customAttributeProvider = _attributeProvider;
if (customAttributeProvider == null) {
MethodBase methodBase = MatchingProperty.DeclaringTypeInfo.ConstructorAttributeProvider as MethodBase;
if ((object)methodBase != null) {
ParameterInfo[] parameters = methodBase.GetParameters();
if (Position < parameters.Length)
customAttributeProvider = (_attributeProvider = parameters[Position]);
}
}
return customAttributeProvider;
}
}
internal JsonPropertyInfo MatchingProperty { get; }
internal JsonConverter EffectiveConverter => MatchingProperty.EffectiveConverter;
internal bool IgnoreNullTokensOnRead => MatchingProperty.IgnoreNullTokensOnRead;
internal JsonSerializerOptions Options => MatchingProperty.Options;
internal byte[] JsonNameAsUtf8Bytes => MatchingProperty.NameAsUtf8Bytes;
internal JsonNumberHandling? NumberHandling => MatchingProperty.EffectiveNumberHandling;
internal JsonTypeInfo JsonTypeInfo => MatchingProperty.JsonTypeInfo;
internal bool ShouldDeserialize => !MatchingProperty.IsIgnored;
internal bool IsRequiredParameter {
get {
if (!HasDefaultValue)
return !IsMemberInitializer;
return false;
}
}
internal JsonParameterInfo(JsonParameterInfoValues parameterInfoValues, JsonPropertyInfo matchingProperty)
{
Position = parameterInfoValues.Position;
Name = parameterInfoValues.Name;
HasDefaultValue = parameterInfoValues.HasDefaultValue;
DefaultValue = (parameterInfoValues.HasDefaultValue ? parameterInfoValues.DefaultValue : null);
MatchingProperty = matchingProperty;
IsMemberInitializer = parameterInfoValues.IsMemberInitializer;
}
}
}