The description of the returned enumeration value returns all values, literals, and descriptions in the type based on the enumeration type

Source: Internet
Author: User

<summary>////Returns the description of the enumeration value///</summary>//<param name= "Value" > enumeration value </param>        <returns> Specify enumeration value description </returns> public static string Getenumdescription (this enum value) {FieldInfo fi = value. GetType (). GetField (value.            ToString ()); if (fi = = null) {return value.            ToString (); } object[] attributes = fi.            GetCustomAttributes (typeof (Enumdescriptionattribute), false); if (attributes = = NULL | | attributes. Length = = 0) {return value.            ToString (); } else {string[] arr = ((Enumdescriptionattribute) attributes[0]).                Description.split (new string[] {","}, Stringsplitoptions.none);            return Appcommon.convertlanguage (arr); }}///<summary>//Returns all values, text, and descriptions in the type, based on enumeration type///</summary>// <param NAMe= "type" ></param>///<returns> returns three-column array, NO. 0 listed as description, 1th column value, 2nd Column text</returns> Pub Lic static list<enumoperation> getenumopt (type type) {list<enumoperation> ret = new List&lt ;            Enumoperation> (); fieldinfo[] fields = type.            GetFields (); for (int i = 1, count = fields. Length; I < count;                i++) {Enumoperation eo = new enumoperation ();                FieldInfo field = Fields[i]; enumeration value Eo.value = (int) enum.parse (type, field.                                Name); Enumeration name Eo.name = field.                Name; Enumeration description Information object[] objs = field.                GetCustomAttributes (typeof (Isip.assembly.EnumDescriptionAttribute), false); if (OBJS = = NULL | | objs. Length = = 0) {eo.desc = field.                Name; } else {Isip.assembly.EnumDescripTionattribute da = (isip.assembly.EnumDescriptionAttribute) objs[0]; string[] arr = da.                    Description.split (new string[] {","}, Stringsplitoptions.none);                Eo.desc = Appcommon.convertlanguage (arr); } ret.            ADD (EO);        } return ret;        }[serializable] public class Enumoperation {public string name {get; set;}        public string desc {get; set;}        public int value {get; set;}    Public dictionary<string, int[]> section {get; set;} }

  

The description of the returned enumeration value returns all values, literals, and descriptions in the type based on the enumeration type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.