What value__
might be here?
value__
MSN
ICQ
YahooChat
GoogleTalk
The code I ran is simple:
namespace EnumReflection
{
enum Messengers
{
MSN,
ICQ,
YahooChat,
GoogleTalk
}
class Program
{
static void Main(string[] args)
{
FieldInfo[] fields = typeof(Messengers).GetFields();
foreach (var field in fields)
{
Console.WriteLine(field.Name);
}
Console.ReadLine();
}
}
}
You can find more here. The poster even has sample code that should get you around the problem... just insert BindingFlags.Public | BindingFlags.Static in between the parentheses of GetFields().
By using reflection, I figured I would gain the upper hand and take control of my enum woes. Unfortunately, calling GetFields on an enum type adds an extra entry named value__ to the returned list. After browsing through the decompilation of Enum, I found that value__ is just a special instance field used by the enum to hold the value of the selected member. I also noticed that the actual enum members are really marked as static. So, to get around this problem, all you need to do is call GetFields with the BindingFlags set to only retrieve the public, static fields
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With