<PackageReference Include="System.Text.Json" Version="10.0.0-preview.1.25080.5" />

JsonNumberEnumConverter<TEnum>

public sealed class JsonNumberEnumConverter<TEnum> : JsonConverterFactory where TEnum : struct, Enum
Converter to convert enums to and from numeric values.
using System.Runtime.CompilerServices; using System.Text.Json.Serialization.Converters; namespace System.Text.Json.Serialization { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public sealed class JsonNumberEnumConverter<[System.Runtime.CompilerServices.Nullable(0)] TEnum> : JsonConverterFactory where TEnum : struct, Enum { public override bool CanConvert(Type typeToConvert) { return typeToConvert == typeof(TEnum); } [return: System.Runtime.CompilerServices.Nullable(2)] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { if (typeToConvert != typeof(TEnum)) ThrowHelper.ThrowArgumentOutOfRangeException_JsonConverterFactory_TypeNotSupported(typeToConvert); return EnumConverterFactory.Helpers.Create<TEnum>(EnumConverterOptions.AllowNumbers, options, (JsonNamingPolicy)null); } } }