What I want to do is something like this: I have enums with combined flagged values.
public static class EnumExtension
{
public static bool IsSet
As of C# 7.3, you can use the Enum constraint on generic types:
public static TEnum Parse(string value) where TEnum : Enum
{
return (TEnum) Enum.Parse(typeof(TEnum), value);
}
If you want to use a Nullable enum, you must leave the orginial struct constraint:
public static TEnum? TryParse(string value) where TEnum : struct, Enum
{
if( Enum.TryParse(value, out TEnum res) )
return res;
else
return null;
}