K
Ken Allen
I have a need to convert the names of the members of an enumeration into an
array of strings at runtime.
I have determined a method using reflection.
Type theType = typeof(MyEnumName);
MemberInfo[] theMembers = theType.getMembers();
foreach (MemberInfo entry in theMembers)
{
if ((entry.MemberType.ToString() == "Field") && (entry.Name !=
"value__))
{
// add this entry.Name to the list
}
}
Unfortunately this method means that I do not know how many members there
are in the enumeration until I have scanned the entire MemberInfo array.
Is there a simpler or more direct method for achieving this?
-ken
array of strings at runtime.
I have determined a method using reflection.
Type theType = typeof(MyEnumName);
MemberInfo[] theMembers = theType.getMembers();
foreach (MemberInfo entry in theMembers)
{
if ((entry.MemberType.ToString() == "Field") && (entry.Name !=
"value__))
{
// add this entry.Name to the list
}
}
Unfortunately this method means that I do not know how many members there
are in the enumeration until I have scanned the entire MemberInfo array.
Is there a simpler or more direct method for achieving this?
-ken