///<summary> /// Converter to convert enums to and from strings. ///</summary> ///<remarks> /// Reading is case insensitive, writing can be customized via a <see cref="JsonNamingPolicy" />. ///</remarks> [RequiresDynamicCode( "JsonStringEnumConverter cannot be statically analyzed and requires runtime code generation. " + "Applications should use the generic JsonStringEnumConverter<TEnum> instead.")] publicclassJsonStringEnumConverter : JsonConverterFactory { privatereadonly JsonNamingPolicy? _namingPolicy; privatereadonly EnumConverterOptions _converterOptions;
///<summary> /// Constructor. Creates the <see cref="JsonStringEnumConverter"/> with the /// default naming policy and allows integer values. ///</summary> publicJsonStringEnumConverter() : this(namingPolicy: null, allowIntegerValues: true) { // An empty constructor is needed for construction via attributes }
///<summary> /// Constructor. ///</summary> ///<param name="namingPolicy"> /// Optional naming policy for writing enum values. ///</param> ///<param name="allowIntegerValues"> /// True to allow undefined enum values. When true, if an enum value isn't /// defined it will output as a number rather than a string. ///</param> publicJsonStringEnumConverter(JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { _namingPolicy = namingPolicy; _converterOptions = allowIntegerValues ? EnumConverterOptions.AllowNumbers | EnumConverterOptions.AllowStrings : EnumConverterOptions.AllowStrings; }