Get enumeration Description Information (Description)
See other people's enum has a Get enumeration description information (Description), directly to their own add, found not work. Look for a search on the net, originally want this kind of add:
1. Defining an Enum
Using System;
Using System.ComponentModel;
public enum TimeOfDay
{
[Description ("Morning")]
moning = 0,
[Description ("noon")]
Afternoon = 1,
[Description ("Evening")]
Evening = 2,
};
2. Gets the descriptive information for the enum. Return with NameValueCollection.
The key value of the NameValueCollection equals the key of the enum.
Using System;
Using System.Reflection;
Using System.ComponentModel;
Using System.Collections.Specialized;
<summary>
Get the attribute value of an enum
</summary>
<returns></returns>
public static NameValueCollection Convertenumdescriptionvalue ()
{
NameValueCollection NVC = new NameValueCollection ();
Type type = typeof (DescriptionAttribute);
foreach (FieldInfo fi in typeof (Enumclass.timeofday). GetFields ())
{
object[] arr = fi. GetCustomAttributes (type, true);
if (arr. Length > 0)
{
Nvc. Add (FI. Name, ((DescriptionAttribute) arr[0]). Description);
}
}
return NVC;
}