Skip to content

Instantly share code, notes, and snippets.


Alexej Kowalew 616b2f

View GitHub Profile
616b2f / StringEnumConverter.cs
Last active Jun 6, 2019
Generic StringEnumConverter<T> for C# version < 7.3
View StringEnumConverter.cs
using System;
using System.Reflection;
using Newtonsoft.Json.Converters;
public class StringEnumConverter<TEnum> : StringEnumConverter where TEnum : struct, IConvertible
public override bool CanConvert(Type objectType)
Type t = Nullable.GetUnderlyingType(objectType) ?? objectType;
return t.IsEnum && t == typeof(TEnum);