< Summary

Information
Class: System.Text.Json.Serialization.JsonSourceGenerationOptionsAttribute
Assembly: System.Text.Json
File(s): C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\Common\JsonSourceGenerationOptionsAttribute.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 186
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(...)0%660%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\Common\JsonSourceGenerationOptionsAttribute.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
 4namespace System.Text.Json.Serialization
 5{
 6    /// <summary>
 7    /// Specifies compile-time source generator configuration when applied to <see cref="JsonSerializerContext"/> class 
 8    /// </summary>
 9    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
 10#if BUILDING_SOURCE_GENERATOR
 11    internal
 12#else
 13    public
 14#endif
 15    sealed class JsonSourceGenerationOptionsAttribute : JsonAttribute
 16    {
 17        /// <summary>
 18        /// Constructs a new <see cref="JsonSourceGenerationOptionsAttribute"/> instance.
 19        /// </summary>
 020        public JsonSourceGenerationOptionsAttribute() { }
 21
 22        /// <summary>
 23        /// Constructs a new <see cref="JsonSourceGenerationOptionsAttribute"/> instance with a predefined set of option
 24        /// </summary>
 25        /// <param name="defaults">The <see cref="JsonSerializerDefaults"/> to reason about.</param>
 26        /// <exception cref="ArgumentOutOfRangeException">Invalid <paramref name="defaults"/> parameter.</exception>
 027        public JsonSourceGenerationOptionsAttribute(JsonSerializerDefaults defaults)
 028        {
 29            // Constructor kept in sync with equivalent overload in JsonSerializerOptions
 30
 031            if (defaults is JsonSerializerDefaults.Web)
 032            {
 033                PropertyNameCaseInsensitive = true;
 034                PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase;
 035                NumberHandling = JsonNumberHandling.AllowReadingFromString;
 036            }
 037            else if (defaults is JsonSerializerDefaults.Strict)
 038            {
 039                UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow;
 040                AllowDuplicateProperties = false;
 041                RespectNullableAnnotations = true;
 042                RespectRequiredConstructorParameters = true;
 043            }
 044            else if (defaults is not JsonSerializerDefaults.General)
 045            {
 046                throw new ArgumentOutOfRangeException(nameof(defaults));
 47            }
 048        }
 49
 50        /// <summary>
 51        /// Specifies the default value of <see cref="JsonSerializerOptions.AllowOutOfOrderMetadataProperties"/> when se
 52        /// </summary>
 053        public bool AllowOutOfOrderMetadataProperties { get; set; }
 54
 55        /// <summary>
 56        /// Specifies the default value of <see cref="JsonSerializerOptions.AllowTrailingCommas"/> when set.
 57        /// </summary>
 058        public bool AllowTrailingCommas { get; set; }
 59
 60        /// <summary>
 61        /// Specifies the default value of <see cref="JsonSerializerOptions.Converters"/> when set.
 62        /// </summary>
 063        public Type[]? Converters { get; set; }
 64
 65        /// <summary>
 66        /// Specifies the default value of <see cref="JsonSerializerOptions.DefaultBufferSize"/> when set.
 67        /// </summary>
 068        public int DefaultBufferSize { get; set; }
 69
 70        /// <summary>
 71        /// Specifies the default value of <see cref="JsonSerializerOptions.DefaultIgnoreCondition"/> when set.
 72        /// </summary>
 073        public JsonIgnoreCondition DefaultIgnoreCondition { get; set; }
 74
 75        /// <summary>
 76        /// Specifies the default value of <see cref="JsonSerializerOptions.DictionaryKeyPolicy"/> when set.
 77        /// </summary>
 078        public JsonKnownNamingPolicy DictionaryKeyPolicy { get; set; }
 79
 80        /// <summary>
 81        /// Specifies the default value of <see cref="JsonSerializerOptions.IgnoreReadOnlyFields"/> when set.
 82        /// </summary>
 083        public bool IgnoreReadOnlyFields { get; set; }
 84
 85        /// <summary>
 86        /// Specifies the default value of <see cref="JsonSerializerOptions.IgnoreReadOnlyProperties"/> when set.
 87        /// </summary>
 088        public bool IgnoreReadOnlyProperties { get; set; }
 89
 90        /// <summary>
 91        /// Specifies the default value of <see cref="JsonSerializerOptions.IncludeFields"/> when set.
 92        /// </summary>
 093        public bool IncludeFields { get; set; }
 94
 95        /// <summary>
 96        /// Specifies the default value of <see cref="JsonSerializerOptions.MaxDepth"/> when set.
 97        /// </summary>
 098        public int MaxDepth { get; set; }
 99
 100        /// <summary>
 101        /// Specifies the default value of <see cref="JsonSerializerOptions.NumberHandling"/> when set.
 102        /// </summary>
 0103        public JsonNumberHandling NumberHandling { get; set; }
 104
 105        /// <summary>
 106        /// Specifies the default value of <see cref="JsonSerializerOptions.PreferredObjectCreationHandling"/> when set.
 107        /// </summary>
 0108        public JsonObjectCreationHandling PreferredObjectCreationHandling { get; set; }
 109
 110        /// <summary>
 111        /// Specifies the default value of <see cref="JsonSerializerOptions.PropertyNameCaseInsensitive"/> when set.
 112        /// </summary>
 0113        public bool PropertyNameCaseInsensitive { get; set; }
 114
 115        /// <summary>
 116        /// Specifies the default value of <see cref="JsonSerializerOptions.PropertyNamingPolicy"/> when set.
 117        /// </summary>
 0118        public JsonKnownNamingPolicy PropertyNamingPolicy { get; set; }
 119
 120        /// <summary>
 121        /// Specifies the default value of <see cref="JsonSerializerOptions.ReadCommentHandling"/> when set.
 122        /// </summary>
 0123        public JsonCommentHandling ReadCommentHandling { get; set; }
 124
 125        /// <summary>
 126        /// Specifies the default value of <see cref="JsonSerializerOptions.ReferenceHandler"/> when set.
 127        /// </summary>
 0128        public JsonKnownReferenceHandler ReferenceHandler { get; set; }
 129
 130        /// <summary>
 131        /// Specifies the default value of <see cref="JsonSerializerOptions.RespectNullableAnnotations"/> when set.
 132        /// </summary>
 0133        public bool RespectNullableAnnotations { get; set; }
 134
 135        /// <summary>
 136        /// Specifies the default value of <see cref="JsonSerializerOptions.RespectRequiredConstructorParameters"/> when
 137        /// </summary>
 0138        public bool RespectRequiredConstructorParameters { get; set; }
 139
 140        /// <summary>
 141        /// Specifies the default value of <see cref="JsonSerializerOptions.UnknownTypeHandling"/> when set.
 142        /// </summary>
 0143        public JsonUnknownTypeHandling UnknownTypeHandling { get; set; }
 144
 145        /// <summary>
 146        /// Specifies the default value of <see cref="JsonSerializerOptions.UnmappedMemberHandling"/> when set.
 147        /// </summary>
 0148        public JsonUnmappedMemberHandling UnmappedMemberHandling { get; set; }
 149
 150        /// <summary>
 151        /// Specifies the default value of <see cref="JsonSerializerOptions.WriteIndented"/> when set.
 152        /// </summary>
 0153        public bool WriteIndented { get; set; }
 154
 155        /// <summary>
 156        /// Specifies the default value of <see cref="JsonSerializerOptions.IndentCharacter"/> when set.
 157        /// </summary>
 0158        public char IndentCharacter { get; set; }
 159
 160        /// <summary>
 161        /// Specifies the default value of <see cref="JsonSerializerOptions.IndentCharacter"/> when set.
 162        /// </summary>
 0163        public int IndentSize { get; set; }
 164
 165        /// <summary>
 166        /// Specifies the default source generation mode for type declarations that don't set a <see cref="JsonSerializa
 167        /// </summary>
 0168        public JsonSourceGenerationMode GenerationMode { get; set; }
 169
 170        /// <summary>
 171        /// Instructs the source generator to default to <see cref="JsonStringEnumConverter"/>
 172        /// instead of numeric serialization for all enum types encountered in its type graph.
 173        /// </summary>
 0174        public bool UseStringEnumConverter { get; set; }
 175
 176        /// <summary>
 177        /// Specifies the default value of <see cref="JsonSerializerOptions.NewLine"/> when set.
 178        /// </summary>
 0179        public string? NewLine { get; set; }
 180
 181        /// <summary>
 182        /// Specifies the default value of <see cref="JsonSerializerOptions.AllowDuplicateProperties"/> when set.
 183        /// </summary>
 0184        public bool AllowDuplicateProperties { get; set; }
 185    }
 186}