.net将枚举转成List

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<EnumberEntity>(); foreach (var e in Enum.GetValues(typeof(T)))
{
EnumberEntity m = new EnumberEntity();
object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
if(objArr!=null && objArr.Length>)
{
DescriptionAttribute da = objArr[] as DescriptionAttribute;
m.Desction = da.Description;
}
m.EnumValue = Convert.ToInt32(e);
m.EnumName = e.ToString();
list.Add(m);
}
return list;
}
} public class EnumberEntity
{
/// <summary>
/// 枚举的描述
/// </summary>
public string Desction { set; get; } /// <summary>
/// 枚举名称
/// </summary>
public string EnumName { set; get; } /// <summary>
/// 枚举对象的值
/// </summary>
public int EnumValue { set; get; }
}
}
public enum QxItem
{
[Description("查看")]
Show=,
[Description("新增")]
Add=,
[Description("编辑")]
Edit=,
[Description("删除")]
Del=,
[Description("审批")]
Sp=,
[Description("导出")]
Export=,
[Description("同步")]
Sync=,
[Description("打印")]
Print=
}
上一篇:.NET Framework 2.0/3.0/3.5 以 v90 平台工具集为目标。请确保在计算机上安装了 Visual Studio 2008


下一篇:Python中元组,列表,字典的区别