< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 98
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonTypeClassifierContext.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.Collections.Generic;
 5using System.Text.Json.Serialization.Metadata;
 6
 7namespace System.Text.Json.Serialization
 8{
 9    /// <summary>
 10    /// Provides immutable metadata to a <see cref="JsonTypeClassifierFactory"/> when
 11    /// creating a <see cref="JsonTypeClassifier"/> delegate.
 12    /// </summary>
 13    /// <remarks>
 14    /// <para>
 15    /// The context carries a <see cref="Kind"/> value indicating whether the classifier
 16    /// is being created for a union type or a polymorphic type. Exactly one of the two
 17    /// candidate lists is populated for any given context.
 18    /// </para>
 19    /// <para>
 20    /// Instances are created internally by the serialization infrastructure. Users
 21    /// interact with the context through a <see cref="JsonTypeClassifierFactory"/>
 22    /// implementation.
 23    /// </para>
 24    /// </remarks>
 25    public sealed class JsonTypeClassifierContext
 26    {
 27        /// <summary>
 28        /// Initializes a new instance of the <see cref="JsonTypeClassifierContext"/> class.
 29        /// </summary>
 30        /// <param name="kind">The type of classifier metadata being configured.</param>
 31        /// <param name="declaringTypeInfo">The contract being configured for classification.</param>
 32        /// <param name="unionCases">The union cases of the declaring type, or an empty list.</param>
 33        /// <param name="derivedTypes">The derived types of the declaring type, or an empty list.</param>
 34        /// <param name="typeDiscriminatorPropertyName">The JSON property name used for type discrimination, or <see lan
 035        internal JsonTypeClassifierContext(
 036            JsonTypeClassifierKind kind,
 037            JsonTypeInfo declaringTypeInfo,
 038            IReadOnlyList<JsonUnionCaseInfo> unionCases,
 039            IReadOnlyList<JsonDerivedType> derivedTypes,
 040            string? typeDiscriminatorPropertyName)
 041        {
 042            Kind = kind;
 043            DeclaringTypeInfo = declaringTypeInfo;
 044            UnionCases = unionCases;
 045            DerivedTypes = derivedTypes;
 046            TypeDiscriminatorPropertyName = typeDiscriminatorPropertyName;
 047        }
 48
 49        /// <summary>
 50        /// Gets the type of classifier metadata being configured.
 51        /// </summary>
 052        public JsonTypeClassifierKind Kind { get; }
 53
 54        /// <summary>
 55        /// Gets the type being configured for classification.
 56        /// </summary>
 57        /// <remarks>
 58        /// For polymorphic types, this is the base class (e.g., <c>Animal</c>).
 59        /// For union types, this is the union type (e.g., <c>IntOrString</c>).
 60        /// </remarks>
 061        public Type DeclaringType => DeclaringTypeInfo.Type;
 62
 63        // The contract may still be mutable when a modifier reads TypeClassifier.
 064        internal JsonTypeInfo DeclaringTypeInfo { get; }
 65
 66        /// <summary>
 67        /// Gets the union cases of <see cref="DeclaringType"/>.
 68        /// </summary>
 69        /// <remarks>
 70        /// Non-empty when <see cref="DeclaringType"/> is configured as a union type. The
 71        /// list mirrors <see cref="JsonTypeInfo.UnionCases"/> on the resolved
 72        /// <see cref="JsonTypeInfo"/>.
 73        /// </remarks>
 074        public IReadOnlyList<JsonUnionCaseInfo> UnionCases { get; }
 75
 76        /// <summary>
 77        /// Gets the derived types of <see cref="DeclaringType"/>.
 78        /// </summary>
 79        /// <remarks>
 80        /// Non-empty when <see cref="DeclaringType"/> is configured as a polymorphic
 81        /// type. The list mirrors
 82        /// <see cref="Metadata.JsonPolymorphismOptions.DerivedTypes"/>; each entry may
 83        /// carry a <see cref="JsonDerivedType.TypeDiscriminator"/> string or integer.
 84        /// </remarks>
 085        public IReadOnlyList<JsonDerivedType> DerivedTypes { get; }
 86
 87        /// <summary>
 88        /// Gets the JSON property name used for type discrimination (e.g., <c>"$type"</c>, <c>"kind"</c>).
 89        /// </summary>
 90        /// <remarks>
 91        /// Populated from <see cref="Metadata.JsonPolymorphismOptions.TypeDiscriminatorPropertyName"/>
 92        /// for polymorphic types. <see langword="null"/> for union types (unions don't use
 93        /// discriminator properties by default).
 94        /// </remarks>
 095        public string? TypeDiscriminatorPropertyName { get; }
 96    }
 97}
 98