<summary>///political appearance ///</summary>public enum Eumpoliticsstatus { [Display (Name = "Party Member")] Partymember = 1, [Display (name = "League Member")] Member = 2, [Display (name = "mass")] masses = 3, [Display (name = "Democratic Party")] Democraticparty = 4}
Defining enumerations First
public static string Getenumdesc (Enum en) { Type type = en. GetType (); memberinfo[] Meminfo = type. GetMember (en. ToString ()); if (meminfo! = null && meminfo.length > 0) {object[] attrs = meminfo[0]. GetCustomAttributes (typeof (System.ComponentModel.DataAnnotations.DisplayAttribute), false); if (attrs! = null & & Attrs. Length > 0) return ((System.ComponentModel.DataAnnotations.DisplayAttribute) attrs[0]). Name; } Return en. ToString (); }
The above method uses reflection to get the value of name in display based on the enumerated value passed in.
var name =getenumdesc (Eumpoliticsstatus.partymember),