< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 53
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%
.ctor()100%110%
CreateConverter(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonConverterAttribute.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.CodeAnalysis;
 5
 6namespace System.Text.Json.Serialization
 7{
 8    /// <summary>
 9    /// When placed on a property, field, or type, specifies the converter type to use.
 10    /// </summary>
 11    /// <remarks>
 12    /// The specified converter type must derive from <see cref="JsonConverter"/>.
 13    /// When placed on a property or field, the specified converter will always be used.
 14    /// When placed on a type, the specified converter will be used unless a compatible converter is added to
 15    /// <see cref="JsonSerializerOptions.Converters"/> or there is another <see cref="JsonConverterAttribute"/> on a pro
 16    /// of the same type.
 17    /// </remarks>
 18    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enu
 19    public class JsonConverterAttribute : JsonAttribute
 20    {
 21        /// <summary>
 22        /// Initializes a new instance of <see cref="JsonConverterAttribute"/> with the specified converter type.
 23        /// </summary>
 24        /// <param name="converterType">The type of the converter.</param>
 025        public JsonConverterAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessCons
 026        {
 027            ConverterType = converterType;
 028        }
 29
 30        /// <summary>
 31        /// Initializes a new instance of <see cref="JsonConverterAttribute"/>.
 32        /// </summary>
 033        protected JsonConverterAttribute() { }
 34
 35        /// <summary>
 36        /// The type of the converter to create, or null if <see cref="CreateConverter(Type)"/> should be used to obtain
 37        /// </summary>
 38        [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
 039        public Type? ConverterType { get; }
 40
 41        /// <summary>
 42        /// If overridden and <see cref="ConverterType"/> is null, allows a custom attribute to create the converter in 
 43        /// </summary>
 44        /// <returns>
 45        /// The custom converter.
 46        /// </returns>
 47        public virtual JsonConverter? CreateConverter(Type typeToConvert)
 048        {
 049            return null;
 050        }
 51    }
 52}
 53