public static int GetEnumValue(Type enumType, string enumName) { try { if (!enumType.IsEnum) throw new ArgumentException("enumType必须是枚举类型"); var values = Enum.GetValues(enumType); var ht = new Hashtable(); foreach(var val in values) { ht.Add(Enu
关键代码: 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
我们需要获取类,属性,方法的描述.这个跟获取枚举的描述一样,需要我们通过反射来做.这还需要我们的利用System.ComponentModel:Description 的属性来完成. 新建一个类:使用的是: System.ComponentModel:Description [Description("类的描述")] public class TestDes { [Description("id值")] public int Id { get; set; } [
封装了方法: public static class EnumOperate { public class BaseDescriptionAttribute : DescriptionAttribute { public BaseDescriptionAttribute(string descriptionCN) : base(descriptionCN) { } public BaseDescriptionAttribute(string descriptionCN, string descr
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace candel { class Program { static void Main(string[] args) { int x = (in
代码: 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