public enum FileCode { /// <summary> /// 申請表 /// </summary> [Description("申請表")] A001 } public class GetEnumDescription { public static string GetEnumName<T>(string value) where T : new() { Type t = typeof (T); foreach (MemberInfo mInfo in t.GetMembers()) { var str = t.GetEnumNames(); var query = str.Where(e => e.Equals(value)); if (query.Any() && mInfo.Name == query.ToList()[0]) { foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo)) { if (attr.GetType() == typeof (DescriptionAttribute)) { return ((DescriptionAttribute) attr).Description; } } } } return ""; } }
通過反射讀取枚舉類型的描述信息