第一步:定义顶级枚举接口 public interface BaseEnum<E extends Enum<?>, T> { public T getCode(); public String getValue(); } 第二步:实现枚举接口 public enum AccountTypeEnum implements BaseEnum<AccountTypeEnum,Integer>{ PERSONAL(1,"PERSONAL"), ORGANIZ…
using System; using System.Collections.Generic; using System.ComponentModel; namespace zifar.SgmhWeb.CommonMethod { public class EnumberHelper { public static List<EnumberEntity> EnumToList<T>() { List<EnumberEntity> list = new List<E…
1.拓展EnumHelper public static class EnumHelper { // Get the value of the description attribute if the // enum has one, otherwise use the value. public static string GetDescription<TEnum>(this TEnum value) { var fi = value.GetType().GetField(value.ToS…
C#里面经常会用到枚举类型,枚举是值类型对象,如果你想用枚举类型的多属性特性,或者你想在MVC页面上通过简单的值类型转换,将某字段值所代表的含义转换为文字显示,这时候必须要将枚举扩展,是它支持文本描述属性,或者显示名称属性,亦或者多语言支持.例如同一个值类型的字段值,你想让它显示中文描述,英文描述…… 请看下面的扩展示例: using System; using System.Collections.Generic; using System.Linq; using System.Ref…