options.JsonSerializerOptions.Converters.Add(newJsonStringEnumConverter()); }); 源码地址 https://github.com/dotnet/runtime/blob/master/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs // Licensed to the .NET Foundation under one or more agreements.// Th...
Converter to convert enums to and from strings. C# publicclassJsonStringEnumConverter<TEnum> :System.Text.Json.Serialization.JsonConverterFactorywhereTEnum:struct Type Parameters TEnum The enum type that this converter targets. Remarks Reading is case insensitive, and writing can be customized via a...
Espacio de nombres: System.Text.Json.Serialization Ensamblado: System.Text.Json.dll Source: JsonStringEnumConverter.cs Determina si el tipo especificado puede convertirse en una enumeración. C# Copiar public override sealed bool CanConvert (Type typeToConvert); Parámetros typ...
JsonStringEnumConverter() 整数値を許可する既定の名前付けポリシーを使用して、JsonStringEnumConverterクラスのインスタンスを初期化します。 JsonStringEnumConverter(JsonNamingPolicy, Boolean) 指定された名前付けポリシーと、未定義の列挙値を許可するかどうかを示す値を使用して、JsonStringEnumConve...
Calling{publicenumCallingAction{LoadImage,Points,}[JsonConverter(typeof(StringEnumConverter))]publicCallingActionAction{get;set;}=CallingAction.LoadImage;publicstringJsonData{get;set;}} privatevoidAwake(){AotHelper.EnsureType<StringEnumConverter>();} ...
JsonStringEnumConverter.CanConvert(Type) 方法参考 反馈 定义命名空间: System.Text.Json.Serialization 程序集: System.Text.Json.dll 确定是否可将指定类型转换为枚举。 C# 复制 public override sealed bool CanConvert (Type typeToConvert); 参数 typeToConvert Type 要检查的类型。 返回 Boolean 如果...
我可以弄清楚告诉框架应用的唯一方法StringEnumConverter是对有问题的属性进行如下注释:[JsonConverter(typeof(StringEnumConverter))]public virtual MyEnums MyEnum { get; set; }但是,在我的用例中,全局配置json.net会更加方便,这样所有枚举都可以使用进行(反)序列化StringEnumConverter,而无需额外的注释。有没有...
Newtonsoft.Json.Converters.ExpandoObjectConverter Newtonsoft.Json.Converters.KeyValuePairConverter Newtonsoft.Json.Converters.RegexConverter Newtonsoft.Json.Converters.StringEnumConverter Newtonsoft.Json.Converters.VersionConverter Newtonsoft.Json.Converters.XmlNodeConverter Newtonsoft.Json.JsonConverter<T>Json...
Text.Json; public class JsonStringEnumConverter { public static JsonConverter CreateConverter<T>(JsonSerializerOptions options) where T : struct, Enum; } API Usage The API is intended to be used by source-generated code as described above. Alternative Designs My first thought was to add an ...
In ASP.NET Core 2.2 Web API, I had usedNewtonsoft.Json.Converters.StringEnumConverterto convertenumvalues to the enumerator name at API response as shown below. In this case, the serialized JSON in the response looked like{ "status": "Success", "message": "..." }. ...