< Summary

Information
Class: System.Text.Json.Serialization.Metadata.JsonDerivedType
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\JsonDerivedType.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 23
Coverable lines: 23
Total lines: 68
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonDerivedType.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;
 5
 6namespace System.Text.Json.Serialization.Metadata
 7{
 8    /// <summary>
 9    /// Represents a supported derived type defined in the metadata of a polymorphic type.
 10    /// </summary>
 11    public readonly struct JsonDerivedType
 12    {
 13        /// <summary>
 14        /// Specifies a supported derived type without a type discriminator.
 15        /// </summary>
 16        /// <param name="derivedType">The derived type to be supported by the polymorphic type metadata.</param>
 17        public JsonDerivedType(Type derivedType)
 018        {
 019            DerivedType = derivedType;
 020            TypeDiscriminator = null;
 021        }
 22
 23        /// <summary>
 24        /// Specifies a supported derived type with an integer type discriminator.
 25        /// </summary>
 26        /// <param name="derivedType">The derived type to be supported by the polymorphic type metadata.</param>
 27        /// <param name="typeDiscriminator">The type discriminator to be associated with the derived type.</param>
 28        public JsonDerivedType(Type derivedType, int typeDiscriminator)
 029        {
 030            DerivedType = derivedType;
 031            TypeDiscriminator = typeDiscriminator;
 032        }
 33
 34        /// <summary>
 35        /// Specifies a supported derived type with a string type discriminator.
 36        /// </summary>
 37        /// <param name="derivedType">The derived type to be supported by the polymorphic type metadata.</param>
 38        /// <param name="typeDiscriminator">The type discriminator to be associated with the derived type.</param>
 39        public JsonDerivedType(Type derivedType, string typeDiscriminator)
 040        {
 041            DerivedType = derivedType;
 042            TypeDiscriminator = typeDiscriminator;
 043        }
 44
 45        internal JsonDerivedType(Type derivedType, object? typeDiscriminator)
 046        {
 047            Debug.Assert(typeDiscriminator is null or int or string);
 048            DerivedType = derivedType;
 049            TypeDiscriminator = typeDiscriminator;
 050        }
 51
 52        /// <summary>
 53        /// A derived type that should be supported in polymorphic serialization of the declared base type.
 54        /// </summary>
 055        public Type DerivedType { get; }
 56
 57        /// <summary>
 58        /// The type discriminator identifier to be used for the serialization of the subtype.
 59        /// </summary>
 060        public object? TypeDiscriminator { get; }
 61
 62        internal void Deconstruct(out Type derivedType, out object? typeDiscriminator)
 063        {
 064            derivedType = DerivedType;
 065            typeDiscriminator = TypeDiscriminator;
 066        }
 67    }
 68}