转自http://blog.sina.com.cn/s/blog_7e1662b20100x2mt.html
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.ComponentModel; namespace PD.Models { public enum Role : int { /// <summary> /// 管理员 /// </summary> [EnumName("管理员")] Admin = 0, /// <summary> /// 普通用户 /// </summary> [EnumName("用户")] User = 10, /// <summary> /// 监控 /// </summary> [EnumName("监控")] Monitor = 20, } /// <summary> /// 枚举显示属性,自定义特性 /// </summary> public class EnumNameAttribute : Attribute { public string Name { get; private set; } public EnumNameAttribute(string name) { this.Name = name; } } public static class Extensions { public static string GetName(this ICustomAttributeProvider provider) { var attributes = (EnumNameAttribute[])provider.GetCustomAttributes( typeof(EnumNameAttribute), false); return attributes.First().Name; } /// <summary> /// 枚举扩展方法 调用此方法获取枚举属性值(即:管理员,用户,监控) /// </summary> /// <param name="value"></param> /// <returns></returns> public static string ToChinese(this Enum value) { return value.GetType().GetField(value.ToString()).GetName(); } } }