I used a generic method to parse all these enum types, but there is an error, I am not sure how to fix it. Could someone have a great idea? Thanks
public static T TryParseEnum<T>(string value)
{
T t;
bool ok = Enum.TryParse<T>(value, out t);
return t;
}
Error:
The type 'T' must be a non-nullable value type in order to use it as parameter 'TEnum' in the generic type or method 'Enum.TryParse(string, out TEnum)'
Update: Thanks yours help, and I have fixed it a new method.
public static T TryParseEnum<T>(string value) where T : struct
{
T t = default(T);
bool ok = Enum.TryParse<T>(value, out t);
return t;
}