Ted Miller
10/10/2003 12:54:00 AM
Using reflection to parse the type info in an assembly. For enums, how to
get the constant values for the members? The FieldInfo.Value field has the
symbolic value, not the constant value. There's a HasDefault attribute but
no mention I can find about *where* the default value is actually stored.
enum Color {
Red = 1,
Green = 2,
Blue = 3
};
***
static private void ParseEnum(System.Type objType) {
FieldInfo[] arrObjFields = objType.GetFields();
foreach(FieldInfo objField in arrObjFields) {
Console.WriteLine("\t" + objField.Name + " " +
objField.GetValue(objField).ToString());
}
}
results in something like
enum Color {
Red = Red
Green = Green
Blue = Blue
};
Arg! What am I doing wrong?