58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AllBase
|
|
{
|
|
public class EnumHelper
|
|
{
|
|
public static List<EnumMember> GetEnumMember(Type type)
|
|
{
|
|
List<EnumMember> list = new List<EnumMember>();
|
|
foreach (var d in Enum.GetValues(type))
|
|
{
|
|
string desc = (d.GetType().GetField(d.ToString()).GetCustomAttribute(typeof(EnumDescriptionAttribute)) as EnumDescriptionAttribute).Description;
|
|
list.Add(new EnumMember(d.ToString(), (int)d, desc));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
}
|
|
public class EnumMember
|
|
{
|
|
public string Name;
|
|
public int Value;
|
|
public string Description;
|
|
public EnumMember(string name, int value, string description)
|
|
{
|
|
this.Name = name;
|
|
this.Value = value;
|
|
this.Description = description;
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return this.Description;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 枚举注释的自定义属性类
|
|
/// </summary>
|
|
public class EnumDescriptionAttribute : Attribute
|
|
{
|
|
private string m_strDescription;
|
|
public EnumDescriptionAttribute(string strPrinterName)
|
|
{
|
|
m_strDescription = strPrinterName;
|
|
}
|
|
public string Description
|
|
{
|
|
get { return m_strDescription; }
|
|
}
|
|
}
|
|
}
|