关键代码: 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
using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Prog
代码: public class EnumberHelper { public static List<EnumberEntity> EnumToList<T>() { List<EnumberEntity> list = new List<EnumberEntity>(); foreach (var e in Enum.GetValues(typeof(T))) { EnumberEntity m = new EnumberEntity(); object
C#里面经常会用到枚举类型,枚举是值类型对象,如果你想用枚举类型的多属性特性,或者你想在MVC页面上通过简单的值类型转换,将某字段值所代表的含义转换为文字显示,这时候必须要将枚举扩展,是它支持文本描述属性,或者显示名称属性,亦或者多语言支持.例如同一个值类型的字段值,你想让它显示中文描述,英文描述…… 请看下面的扩展示例: using System; using System.Collections.Generic; using System.Linq; using System.Ref
Enum使用 获取枚举属性 注意:扩展方法必须定义为静态类,静态方法中. public enum EnumPatientSource { [Description("住院")] INHOSPITAL = -1, [Description("门诊")] OUTPATIENT = 0, } public static class EnumHelper { public static string ToDescription(this Enum val) { var ty