пятница, 21 ноября 2008 г.
Walking through Enum entries in C#
Sometimes the need appears in make foreach() construction for Enum entries. Here I'll show how to do it.
Type theType = typeof(MyEnum);
MemberInfo[] theMembers = theType.GetMembers();
foreach (MemberInfo entry in theMembers)
{
if ((entry.MemberType.ToString() == "Field"))
if((entry.Name != "value__"))
{
MyEnum theTyp = (MyEnum)Enum.Parse(typeof(MyEnum), entry.Name);
}
}
As earlier I'm trying to present finished solutions ready to use in your own projects. :)
Ярлыки:
.net,
c#,
reflection
Подписаться на:
Комментарии к сообщению (Atom)
0 коммент.:
Отправить комментарий