< Summary

Information
Class: System.Text.Json.Serialization.Metadata.JsonParameterInfo
Assembly: System.Text.Json
File(s): C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonParameterInfo.cs
Line coverage
29%
Covered lines: 12
Uncovered lines: 29
Coverable lines: 41
Total lines: 128
Line coverage: 29.2%
Branch coverage
10%
Covered branches: 1
Total branches: 10
Branch coverage: 10%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonParameterInfo.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Reflection;
 7
 8namespace System.Text.Json.Serialization.Metadata
 9{
 10    /// <summary>
 11    /// Provides JSON serialization-related metadata about a constructor parameter.
 12    /// </summary>
 13    public abstract class JsonParameterInfo
 14    {
 449415        internal JsonParameterInfo(JsonParameterInfoValues parameterInfoValues, JsonPropertyInfo matchingProperty)
 449416        {
 449417            Debug.Assert(matchingProperty.PropertyType == parameterInfoValues.ParameterType);
 18
 449419            Position = parameterInfoValues.Position;
 449420            Name = parameterInfoValues.Name;
 449421            HasDefaultValue = parameterInfoValues.HasDefaultValue;
 449422            DefaultValue = parameterInfoValues.HasDefaultValue ? parameterInfoValues.DefaultValue : null;
 449423            MatchingProperty = matchingProperty;
 449424            IsMemberInitializer = parameterInfoValues.IsMemberInitializer;
 449425        }
 26
 27        /// <summary>
 28        /// Gets the declaring type of the constructor.
 29        /// </summary>
 030        public Type DeclaringType => MatchingProperty.DeclaringType;
 31
 32        /// <summary>
 33        /// Gets the zero-based position of the parameter in the formal parameter list.
 34        /// </summary>
 4835        public int Position { get; }
 36
 37        /// <summary>
 38        /// Gets the type of this parameter.
 39        /// </summary>
 040        public Type ParameterType => MatchingProperty.PropertyType;
 41
 42        /// <summary>
 43        /// Gets the name of the parameter.
 44        /// </summary>
 045        public string Name { get; }
 46
 47        /// <summary>
 48        /// Gets a value indicating whether the parameter has a default value.
 49        /// </summary>
 050        public bool HasDefaultValue { get; }
 51
 52        /// <summary>
 53        /// Gets a value indicating the default value if the parameter has a default value.
 54        /// </summary>
 055        public object? DefaultValue { get; }
 56
 57        /// <summary>
 58        /// The default value to be passed to the constructor argument array, replacing null with default(TParameter).
 59        /// </summary>
 454260        internal object? EffectiveDefaultValue { get; private protected init; }
 61
 62        /// <summary>
 63        /// Gets a value indicating whether the constructor parameter is annotated as nullable.
 64        /// </summary>
 65        /// <remarks>
 66        /// Contracts originating from <see cref="DefaultJsonTypeInfoResolver"/> or <see cref="JsonSerializerContext"/>,
 67        /// derive the value of this parameter from nullable reference type annotations, including annotations
 68        /// from attributes such as <see cref="AllowNullAttribute"/> or <see cref="DisallowNullAttribute"/>.
 69        ///
 70        /// This property has no effect on deserialization unless the <see cref="JsonSerializerOptions.RespectNullableAn
 71        /// property has been enabled, in which case the serializer will reject any <see langword="null"/> deserializati
 72        ///
 73        /// This setting is in sync with the associated <see cref="JsonPropertyInfo.IsSetNullable"/> property.
 74        /// </remarks>
 075        public bool IsNullable => MatchingProperty.IsSetNullable;
 76
 77        /// <summary>
 78        /// Gets a value indicating whether the parameter represents a required or init-only member initializer.
 79        /// </summary>
 80        /// <remarks>
 81        /// Only returns <see langword="true" /> for source generated metadata which can only access
 82        /// required or init-only member initializers using object initialize expressions.
 83        /// </remarks>
 084        public bool IsMemberInitializer { get; }
 85
 86        /// <summary>
 87        /// Gets a custom attribute provider for the current parameter.
 88        /// </summary>
 89        /// <remarks>
 90        /// When resolving metadata via the built-in resolvers this will be populated with
 91        /// the underlying <see cref="ParameterInfo" /> of the constructor metadata.
 92        /// </remarks>
 93        public ICustomAttributeProvider? AttributeProvider
 94        {
 95            get
 096            {
 97                // Use delayed initialization to ensure that reflection dependencies are pay-for-play.
 098                Debug.Assert(MatchingProperty.DeclaringTypeInfo != null, "Declaring type metadata must have already been
 099                ICustomAttributeProvider? parameterInfo = _attributeProvider;
 0100                if (parameterInfo is null && MatchingProperty.DeclaringTypeInfo.ConstructorAttributeProvider is MethodBa
 0101                {
 0102                    ParameterInfo[] parameters = ctorInfo.GetParameters();
 0103                    if (Position < parameters.Length)
 0104                    {
 0105                        _attributeProvider = parameterInfo = parameters[Position];
 0106                    }
 0107                }
 108
 0109                return parameterInfo;
 0110            }
 111        }
 112
 113        private ICustomAttributeProvider? _attributeProvider;
 114
 0115        internal JsonPropertyInfo MatchingProperty { get; }
 116
 0117        internal JsonConverter EffectiveConverter => MatchingProperty.EffectiveConverter;
 0118        internal bool IgnoreNullTokensOnRead => MatchingProperty.IgnoreNullTokensOnRead;
 0119        internal JsonSerializerOptions Options => MatchingProperty.Options;
 120
 121        // The effective name of the parameter as UTF-8 bytes.
 0122        internal byte[] JsonNameAsUtf8Bytes => MatchingProperty.NameAsUtf8Bytes;
 0123        internal JsonNumberHandling? NumberHandling => MatchingProperty.EffectiveNumberHandling;
 0124        internal JsonTypeInfo JsonTypeInfo => MatchingProperty.JsonTypeInfo;
 0125        internal bool ShouldDeserialize => !MatchingProperty.IsIgnored;
 0126        internal bool IsRequiredParameter => !HasDefaultValue && !IsMemberInitializer;
 127    }
 128}