Class StringEnumConverter
- Namespace
- Cuemon.Extensions.Text.Json.Converters
- Assembly
- Cuemon.Extensions.Text.Json.dll
Converter to convert enums to and from strings.
public class StringEnumConverter : JsonConverterFactory
- Inheritance
-
StringEnumConverter
- Inherited Members
- Extension Methods
Constructors
StringEnumConverter()
Initializes a new instance of the StringEnumConverter class.
public StringEnumConverter()
Methods
CanConvert(Type)
Determines whether the type can be converted.
public override bool CanConvert(Type typeToConvert)
Parameters
typeToConvertTypeThe type is checked whether it can be converted.
Returns
- bool
trueif the type can be converted,falseotherwise.
CreateConverter(Type, JsonSerializerOptions)
Creates a converter for a specified typeToConvert.
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
Parameters
typeToConvertTypeThe Type being converted.
optionsJsonSerializerOptionsThe JsonSerializerOptions being used.
Returns
- JsonConverter
An instance of a JsonConverter<T> where T is compatible with
typeToConvert. If null is returned, a NotSupportedException will be thrown.
Remarks
This is an insane reflection implementation due to, IMO, odd design choice by Microsoft (why have separate namingPolicy when PropertyNamingPolicy is already part of options). Personally I like the NamingStrategy found in Newtonsoft.Json better.