12345678910111213141516171819202122232425262728293031323334353637 |
- using DocumentFormat.OpenXml.Vml;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- namespace Aitex.Core.Utilities
- {
- public class EnumLoop<Key> where Key : struct, IConvertible
- {
- static readonly Key[] arr = (Key[])Enum.GetValues(typeof(Key));
- public static void ForEach(Action<Key> act)
- {
- for (int i = 0; i < arr.Length; i++)
- {
- act(arr[i]);
- }
- }
- }
- public class EnumUtil
- {
- /// <summary>
- /// 获取枚举的描述
- /// </summary>
- /// <param name="val"></param>
- /// <returns></returns>
- public static string GetEnumDescription(Enum val)
- {
- var field = val.GetType().GetField(val.ToString());
- var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
- return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
- }
- }
- }
|