public static class EnumExtension { public static string GetDescription(this Enum value) { FieldInfo field = value.GetType().GetField(value.ToString()); DescriptionAttribute attribute = Attribute.GetCustomAttrib…
C#里面经常会用到枚举类型,枚举是值类型对象,如果你想用枚举类型的多属性特性,或者你想在MVC页面上通过简单的值类型转换,将某字段值所代表的含义转换为文字显示,这时候必须要将枚举扩展,是它支持文本描述属性,或者显示名称属性,亦或者多语言支持.例如同一个值类型的字段值,你想让它显示中文描述,英文描述…… 请看下面的扩展示例: using System; using System.Collections.Generic; using System.Linq; using System.Ref…
关键代码: using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; namespace CSharpUtilHelpV2 { /// <summary> /// 基于.NET 2.0的枚举工具类 /// </summary> public static class EnumToolV2…