1. Use an extension method to use an enumeration value for the Description property value
Public Static classenumextenstion{ Public Static stringGetdescriptionname ( ThisEnum Enumvalue) {Object[] attr =Enumvalue.gettype (). GetField (Enumvalue.tostring ()). GetCustomAttributes (typeof(DescriptionAttribute),false);if(attr. Length >0)return((DescriptionAttribute) attr[0]). Description;return "";}}
2, gets the enumeration Description property value and the enumeration value for the relationship
/// <summary>///gets the collection of relationships for enumeration type description properties and enumeration values (if no descriptive information or description information is empty, no relationship is established)/// </summary>/// <typeparam name= "T" ></typeparam>/// <returns></returns> Public Staticdictionary<string,int> getenumdescriptionandvalue<t>(){varDicfeaturestatusnameid =Newdictionary<string,int>(); Fieldinfo[] Fiarray=typeof(T). GetFields ();foreach(FieldInfo IteminchFiarray) {Object[] Attrs = Item. GetCustomAttributes (typeof(DescriptionAttribute),false);if(Attrs. Length >0)//has Description property{stringDescriptionname = ((DescriptionAttribute) attrs[0]). Description;//Enumeration Description Valueif(!string. Isnullorwhitespace (Descriptionname)&&!Dicfeaturestatusnameid.containskey (Descriptionname)) {intValue = Item. GetValue (typeof(T)). GetHashCode ();//enumeration ValuesDicfeaturestatusnameid.add (descriptionname, value); }}}returnDicfeaturestatusnameid;}
Enum Enum class uses collections