using System.Collections.Generic; using System.Linq; using System.Reflection; namespace VCommon.Reflection { public class EnumMeta { public static IReadOnlyDictionary Meta { get; } static EnumMeta() { if (false == typeof(T).IsEnum) throw new VCommonException("Generic type argument must be Enum."); //TODO: EnumMeta 检查枚举值重复 Meta = typeof(T).GetFields().Where(p => p.FieldType == typeof(T)) .ToDictionary( k => (T)k.GetRawConstantValue(), p => p.GetCustomAttributes(typeof(EnumMetaAttribute)) .OfType() .Single() ); } } }