| | | 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 | | |
| | | 4 | | namespace 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> |
| | 0 | 20 | | 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> |
| | 0 | 27 | | public JsonSourceGenerationOptionsAttribute(JsonSerializerDefaults defaults) |
| | 0 | 28 | | { |
| | | 29 | | // Constructor kept in sync with equivalent overload in JsonSerializerOptions |
| | | 30 | | |
| | 0 | 31 | | if (defaults is JsonSerializerDefaults.Web) |
| | 0 | 32 | | { |
| | 0 | 33 | | PropertyNameCaseInsensitive = true; |
| | 0 | 34 | | PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase; |
| | 0 | 35 | | NumberHandling = JsonNumberHandling.AllowReadingFromString; |
| | 0 | 36 | | } |
| | 0 | 37 | | else if (defaults is JsonSerializerDefaults.Strict) |
| | 0 | 38 | | { |
| | 0 | 39 | | UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow; |
| | 0 | 40 | | AllowDuplicateProperties = false; |
| | 0 | 41 | | RespectNullableAnnotations = true; |
| | 0 | 42 | | RespectRequiredConstructorParameters = true; |
| | 0 | 43 | | } |
| | 0 | 44 | | else if (defaults is not JsonSerializerDefaults.General) |
| | 0 | 45 | | { |
| | 0 | 46 | | throw new ArgumentOutOfRangeException(nameof(defaults)); |
| | | 47 | | } |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Specifies the default value of <see cref="JsonSerializerOptions.AllowOutOfOrderMetadataProperties"/> when se |
| | | 52 | | /// </summary> |
| | 0 | 53 | | public bool AllowOutOfOrderMetadataProperties { get; set; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Specifies the default value of <see cref="JsonSerializerOptions.AllowTrailingCommas"/> when set. |
| | | 57 | | /// </summary> |
| | 0 | 58 | | public bool AllowTrailingCommas { get; set; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Specifies the default value of <see cref="JsonSerializerOptions.Converters"/> when set. |
| | | 62 | | /// </summary> |
| | 0 | 63 | | public Type[]? Converters { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Specifies the default value of <see cref="JsonSerializerOptions.DefaultBufferSize"/> when set. |
| | | 67 | | /// </summary> |
| | 0 | 68 | | public int DefaultBufferSize { get; set; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Specifies the default value of <see cref="JsonSerializerOptions.DefaultIgnoreCondition"/> when set. |
| | | 72 | | /// </summary> |
| | 0 | 73 | | public JsonIgnoreCondition DefaultIgnoreCondition { get; set; } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Specifies the default value of <see cref="JsonSerializerOptions.DictionaryKeyPolicy"/> when set. |
| | | 77 | | /// </summary> |
| | 0 | 78 | | public JsonKnownNamingPolicy DictionaryKeyPolicy { get; set; } |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Specifies the default value of <see cref="JsonSerializerOptions.IgnoreReadOnlyFields"/> when set. |
| | | 82 | | /// </summary> |
| | 0 | 83 | | public bool IgnoreReadOnlyFields { get; set; } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Specifies the default value of <see cref="JsonSerializerOptions.IgnoreReadOnlyProperties"/> when set. |
| | | 87 | | /// </summary> |
| | 0 | 88 | | public bool IgnoreReadOnlyProperties { get; set; } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Specifies the default value of <see cref="JsonSerializerOptions.IncludeFields"/> when set. |
| | | 92 | | /// </summary> |
| | 0 | 93 | | public bool IncludeFields { get; set; } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Specifies the default value of <see cref="JsonSerializerOptions.MaxDepth"/> when set. |
| | | 97 | | /// </summary> |
| | 0 | 98 | | public int MaxDepth { get; set; } |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Specifies the default value of <see cref="JsonSerializerOptions.NumberHandling"/> when set. |
| | | 102 | | /// </summary> |
| | 0 | 103 | | public JsonNumberHandling NumberHandling { get; set; } |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Specifies the default value of <see cref="JsonSerializerOptions.PreferredObjectCreationHandling"/> when set. |
| | | 107 | | /// </summary> |
| | 0 | 108 | | public JsonObjectCreationHandling PreferredObjectCreationHandling { get; set; } |
| | | 109 | | |
| | | 110 | | /// <summary> |
| | | 111 | | /// Specifies the default value of <see cref="JsonSerializerOptions.PropertyNameCaseInsensitive"/> when set. |
| | | 112 | | /// </summary> |
| | 0 | 113 | | public bool PropertyNameCaseInsensitive { get; set; } |
| | | 114 | | |
| | | 115 | | /// <summary> |
| | | 116 | | /// Specifies the default value of <see cref="JsonSerializerOptions.PropertyNamingPolicy"/> when set. |
| | | 117 | | /// </summary> |
| | 0 | 118 | | public JsonKnownNamingPolicy PropertyNamingPolicy { get; set; } |
| | | 119 | | |
| | | 120 | | /// <summary> |
| | | 121 | | /// Specifies the default value of <see cref="JsonSerializerOptions.ReadCommentHandling"/> when set. |
| | | 122 | | /// </summary> |
| | 0 | 123 | | public JsonCommentHandling ReadCommentHandling { get; set; } |
| | | 124 | | |
| | | 125 | | /// <summary> |
| | | 126 | | /// Specifies the default value of <see cref="JsonSerializerOptions.ReferenceHandler"/> when set. |
| | | 127 | | /// </summary> |
| | 0 | 128 | | public JsonKnownReferenceHandler ReferenceHandler { get; set; } |
| | | 129 | | |
| | | 130 | | /// <summary> |
| | | 131 | | /// Specifies the default value of <see cref="JsonSerializerOptions.RespectNullableAnnotations"/> when set. |
| | | 132 | | /// </summary> |
| | 0 | 133 | | public bool RespectNullableAnnotations { get; set; } |
| | | 134 | | |
| | | 135 | | /// <summary> |
| | | 136 | | /// Specifies the default value of <see cref="JsonSerializerOptions.RespectRequiredConstructorParameters"/> when |
| | | 137 | | /// </summary> |
| | 0 | 138 | | public bool RespectRequiredConstructorParameters { get; set; } |
| | | 139 | | |
| | | 140 | | /// <summary> |
| | | 141 | | /// Specifies the default value of <see cref="JsonSerializerOptions.UnknownTypeHandling"/> when set. |
| | | 142 | | /// </summary> |
| | 0 | 143 | | public JsonUnknownTypeHandling UnknownTypeHandling { get; set; } |
| | | 144 | | |
| | | 145 | | /// <summary> |
| | | 146 | | /// Specifies the default value of <see cref="JsonSerializerOptions.UnmappedMemberHandling"/> when set. |
| | | 147 | | /// </summary> |
| | 0 | 148 | | public JsonUnmappedMemberHandling UnmappedMemberHandling { get; set; } |
| | | 149 | | |
| | | 150 | | /// <summary> |
| | | 151 | | /// Specifies the default value of <see cref="JsonSerializerOptions.WriteIndented"/> when set. |
| | | 152 | | /// </summary> |
| | 0 | 153 | | public bool WriteIndented { get; set; } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Specifies the default value of <see cref="JsonSerializerOptions.IndentCharacter"/> when set. |
| | | 157 | | /// </summary> |
| | 0 | 158 | | public char IndentCharacter { get; set; } |
| | | 159 | | |
| | | 160 | | /// <summary> |
| | | 161 | | /// Specifies the default value of <see cref="JsonSerializerOptions.IndentCharacter"/> when set. |
| | | 162 | | /// </summary> |
| | 0 | 163 | | 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> |
| | 0 | 168 | | 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> |
| | 0 | 174 | | public bool UseStringEnumConverter { get; set; } |
| | | 175 | | |
| | | 176 | | /// <summary> |
| | | 177 | | /// Specifies the default value of <see cref="JsonSerializerOptions.NewLine"/> when set. |
| | | 178 | | /// </summary> |
| | 0 | 179 | | public string? NewLine { get; set; } |
| | | 180 | | |
| | | 181 | | /// <summary> |
| | | 182 | | /// Specifies the default value of <see cref="JsonSerializerOptions.AllowDuplicateProperties"/> when set. |
| | | 183 | | /// </summary> |
| | 0 | 184 | | public bool AllowDuplicateProperties { get; set; } |
| | | 185 | | } |
| | | 186 | | } |