Can I cast from a generic type to an enum in C#?
For information, using the generic constraint Enum
is available from C# 7.3 and greater.
Like this:
return (T)(object)value;
Change this:
Enum value = (Enum)Enum.ToObject(enumType, enumAsInt);
to this:
T value = (T)Enum.ToObject(enumType, enumAsInt);
and remove the cast :)