public static T ParseEnum<T>(string value)
{
return (T) Enum.Parse(typeof (T), value, true);
}
I can simply do:
var parsed = EnumUtils.ParseFromString<Gender>("Man");
but sometimes I get type of enum as string. Can i Convert string to enum type and use it in my EnumUtils.
I trid like:
Type enumType = Type.GetType(Gender,true);
Object o = (Activator.CreateInstance(enumType));
var parsed = EnumUtils.ParseFromString<enumType>("Man");
but not working. enumType
is not recognozed in generic way.
I also know for this site: Converting a string to a class name and How do I use reflection to call a generic method?
but does not help me, because I don't know the type of Enum it is not always Gender, can be 100 other enums. I know the name of enum as string and not as type.