JsonSourceGenerationOptionsAttribute
Instructs the System.Text.Json source generator to assume the specified options will be used at run time via JsonSerializerOptions.
using System.Runtime.CompilerServices;
namespace System.Text.Json.Serialization
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class JsonSourceGenerationOptionsAttribute : JsonAttribute
{
public bool AllowOutOfOrderMetadataProperties { get; set; }
public bool AllowTrailingCommas { get; set; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
public Type[] Converters {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
set;
}
public int DefaultBufferSize { get; set; }
public JsonIgnoreCondition DefaultIgnoreCondition { get; set; }
public JsonKnownNamingPolicy DictionaryKeyPolicy { get; set; }
public bool IgnoreReadOnlyFields { get; set; }
public bool IgnoreReadOnlyProperties { get; set; }
public bool IncludeFields { get; set; }
public int MaxDepth { get; set; }
public JsonNumberHandling NumberHandling { get; set; }
public JsonObjectCreationHandling PreferredObjectCreationHandling { get; set; }
public bool PropertyNameCaseInsensitive { get; set; }
public JsonKnownNamingPolicy PropertyNamingPolicy { get; set; }
public JsonCommentHandling ReadCommentHandling { get; set; }
public JsonUnknownTypeHandling UnknownTypeHandling { get; set; }
public JsonUnmappedMemberHandling UnmappedMemberHandling { get; set; }
public bool WriteIndented { get; set; }
public char IndentCharacter { get; set; }
public int IndentSize { get; set; }
public JsonSourceGenerationMode GenerationMode { get; set; }
public bool UseStringEnumConverter { get; set; }
public JsonSourceGenerationOptionsAttribute()
{
}
public JsonSourceGenerationOptionsAttribute(JsonSerializerDefaults defaults)
{
switch (defaults) {
case JsonSerializerDefaults.General:
break;
case JsonSerializerDefaults.Web:
PropertyNameCaseInsensitive = true;
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase;
NumberHandling = JsonNumberHandling.AllowReadingFromString;
break;
default:
throw new ArgumentOutOfRangeException("defaults");
}
}
}
}