Last active
June 6, 2019 13:03
-
-
Save 616b2f/4bc0e90005318eeac103bf171dcbe8d2 to your computer and use it in GitHub Desktop.
Generic StringEnumConverter<T> for C# version < 7.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment