标签:
/// <summary> /// 获取枚举值上的Description特性说明 /// </summary> /// <typeparam name="T">枚举类型</typeparam> /// <param name="obj">枚举值</param> /// <returns></returns> public static string GetDescription<T>(T obj) { Type type = obj.GetType(); FieldInfo field = type.GetField(Enum.GetName(type, obj)); DescriptionAttribute desc = Attribute.GetCustomAttribute (field, typeof(DescriptionAttribute)) as DescriptionAttribute; if(desc == null) { return string.Empty; } return desc.Description; }
标签:
原文地址:http://www.cnblogs.com/ianunspace/p/4784960.html