Example:
class foo
{
byte val = 3;
string EnumName = "boo";
Enum boo : byte
{
coo = 1,
doo = 2,
hoo = 3
}
Enum boo2 : byte
{
eoo = 3,
goo = 8
}
}
How can I do something like this:
Console.WriteLine((GetEnum(EnumName)value).ToString()); // GetEnum is not real
The EnumName will change everytime.
Expected Output:
When Enum Name is boo == "hoo"
When Enum Name is boo2 == "eoo"
Edit: I am going to use this for logging:
Message to boo2.goo
Message to boo.coo
Message to boo.doo
Type.GetTypeand use reflection to get the underlying value, though that will have to be done using a string as it's not a compile time constant..shooafterGetEnum(EnumName)because .NET is statically-typed (except with the newdynamickeyword introduce with C# 4.0). It means that the compiler has to know what type is returned byGetEnum()and this type has to declare a member calledshoo.