@@ -28,13 +28,16 @@ internal sealed class JsonEnumConverterAttribute : JsonConverterAttribute
2828 {
2929 public override JsonConverter CreateConverter ( Type typeToConvert )
3030 {
31- return Activator . CreateInstance ( typeof ( EnumConverter < > ) . MakeGenericType ( typeToConvert ) ) as JsonConverter ;
31+ return Activator . CreateInstance ( typeof ( EnumConverter < > ) . MakeGenericType ( typeToConvert ) )
32+ as JsonConverter ;
3233 }
3334 }
3435
35- internal sealed class EnumConverter < TEnum > : JsonConverter < TEnum > where TEnum : struct
36+ internal sealed class EnumConverter < TEnum > : JsonConverter < TEnum >
37+ where TEnum : struct
3638 {
37- private static Dictionary < Type , MappingConfiguration > _mappings = new Dictionary < Type , MappingConfiguration > ( ) ;
39+ private static Dictionary < Type , MappingConfiguration > _mappings =
40+ new Dictionary < Type , MappingConfiguration > ( ) ;
3841
3942 private struct MappingConfiguration
4043 {
@@ -43,7 +46,6 @@ private struct MappingConfiguration
4346 public Dictionary < TEnum , string > EnumToStringMapping { get ; set ; }
4447 }
4548
46-
4749 private static MappingConfiguration tryGetMappingForType ( Type type )
4850 {
4951 if ( ! EnumConverter < TEnum > . _mappings . ContainsKey ( type ) )
@@ -63,7 +65,8 @@ private static MappingConfiguration tryGetMappingForType(Type type)
6365 FieldInfo memberField = member as FieldInfo ;
6466 if ( memberField != null && memberField . IsStatic && memberField . IsPublic )
6567 {
66- EnumJsonStringValueAttribute attribute = member . GetCustomAttribute < EnumJsonStringValueAttribute > ( ) ;
68+ EnumJsonStringValueAttribute attribute =
69+ member . GetCustomAttribute < EnumJsonStringValueAttribute > ( ) ;
6770 if ( attribute == null )
6871 {
6972 // We've found an element without the attribute
@@ -87,7 +90,9 @@ private static MappingConfiguration getMappingForType(Type type)
8790 MappingConfiguration mapping = EnumConverter < TEnum > . tryGetMappingForType ( type ) ;
8891 if ( ! mapping . MappingIsValid )
8992 {
90- throw new Exception ( $ "Unable to initialize { type } mapping. A member is missing the EnumStringValueAttribute") ;
93+ throw new Exception (
94+ $ "Unable to initialize { type } mapping. A member is missing the EnumStringValueAttribute"
95+ ) ;
9196 }
9297 else
9398 {
@@ -100,7 +105,11 @@ public override bool CanConvert(Type type)
100105 return tryGetMappingForType ( type ) . MappingIsValid ;
101106 }
102107
103- public override TEnum Read ( ref Utf8JsonReader reader , Type type , JsonSerializerOptions options )
108+ public override TEnum Read (
109+ ref Utf8JsonReader reader ,
110+ Type type ,
111+ JsonSerializerOptions options
112+ )
104113 {
105114 MappingConfiguration mapping = EnumConverter < TEnum > . getMappingForType ( type ) ;
106115
@@ -118,12 +127,18 @@ public override TEnum Read(ref Utf8JsonReader reader, Type type, JsonSerializerO
118127 }
119128 }
120129
121- public override void Write ( Utf8JsonWriter writer , TEnum value , JsonSerializerOptions options )
130+ public override void Write (
131+ Utf8JsonWriter writer ,
132+ TEnum value ,
133+ JsonSerializerOptions options
134+ )
122135 {
123136 Type valueType = value . GetType ( ) ;
124137 if ( valueType . IsArray )
125138 {
126- MappingConfiguration mapping = EnumConverter < TEnum > . getMappingForType ( valueType . GetElementType ( ) ) ;
139+ MappingConfiguration mapping = EnumConverter < TEnum > . getMappingForType (
140+ valueType . GetElementType ( )
141+ ) ;
127142 TEnum [ ] typedValueArray = value as TEnum [ ] ;
128143 if ( typedValueArray != null )
129144 {
0 commit comments