I know that to parse a string to specific enum like:
enum AnEnumType
{
TEST_,
OTHER_TEST_,
OTHERS_
}
enum OtherEnumType
{
TEST1_,
OTHER_TEST1_,
OTHERS1_
}
string aValueString = "TEST_";
AnEnumType result = (AnEnumType)Enum.Parse(typeof(AnEnumType), aValueString);
So, I want to create a function, a generic one which use parser for my enum(s) like:
public Type ConvertStringToAnEnum(string value, Type anyType){
return (anyType)Enum.Parse(typeof(anyType), aValueString);
}
But I guess that is not OK…
How to make the function which parse any enumeration type specified as argument in function?
like I want to call OtherEnumType result = ConvertStringToAnEnum("TEST1_", OtherEnumType)
Make the generic method generic:
Usage: