public enum StatuResult
{
[RemarkAttribute (" ")]
WSH = 0,
[RemarkAttribute(" ")]
DSH = 1,
[RemarkAttribute(" ")]
YSH = 9
}
public static Dictionary EnumToDic(string keyDefault="", string valueDefault = "")
{
Dictionary dicEnum = new Dictionary();
Type enumType = typeof(T);
if (!enumType.IsEnum)
{
return dicEnum;
}
if (!string.IsNullOrEmpty(keyDefault)) //
{
dicEnum.Add(keyDefault, valueDefault);
}
string[] fieldstrs = Enum.GetNames(enumType); //
foreach (var item in fieldstrs)
{
string remark = string.Empty;
var field = enumType.GetField(item);
object[] arr = field.GetCustomAttributes(typeof(RemarkAttribute), true); //
RemarkAttribute attr = (RemarkAttribute)arr.FirstOrDefault(a => a is RemarkAttribute);
if (attr == null)
{
remark = field.Name;
}
else
{
remark = attr.Remark;
}
dicEnum.Add(remark, (int)Enum.Parse(enumType, item)); // value key , ,
}
return dicEnum;
}