|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using Fasterflect;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
@ -97,4 +98,41 @@ public static class EnumUtil
|
|
|
|
|
|
|
|
|
|
return enumDic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取得枚举值数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="EnumObject">枚举对象</param>
|
|
|
|
|
/// <returns>枚举值数</returns>
|
|
|
|
|
public static int GetEnumValue(this System.Enum EnumObject)
|
|
|
|
|
{
|
|
|
|
|
int intValue = (int)System.Enum.Parse(EnumObject.GetType(), EnumObject.ToString(), true);
|
|
|
|
|
return intValue;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
|
public static Dictionary<string, int> EnumToDictionary<T>()
|
|
|
|
|
{
|
|
|
|
|
if (!typeof(T).IsEnum)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("T must be an enumerated type");
|
|
|
|
|
}
|
|
|
|
|
var enumDictionary = new Dictionary<string, int>();
|
|
|
|
|
Array enumValues = Enum.GetValues(typeof(T));
|
|
|
|
|
var enumNames = Enum.GetNames(typeof(T));
|
|
|
|
|
foreach (System.Enum value in enumValues)
|
|
|
|
|
{
|
|
|
|
|
enumDictionary.Add(EnumDescription(value), GetEnumValue(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < enumValues.Length; i++)
|
|
|
|
|
//{
|
|
|
|
|
// enumDictionary.Add(EnumDescription(enumNames[i]), (int)enumValues.GetValue(i));
|
|
|
|
|
//}
|
|
|
|
|
return enumDictionary;
|
|
|
|
|
}
|
|
|
|
|
}
|