颐和api

EnumberHelper.cs 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Text;
  5. namespace MadRunFabric.Common.Helpers
  6. {
  7. public class EnumberHelper
  8. {
  9. public static List<EnumberEntity> EnumToList<T>()
  10. {
  11. List<EnumberEntity> list = new List<EnumberEntity>();
  12. foreach (var e in Enum.GetValues(typeof(T)))
  13. {
  14. EnumberEntity m = new EnumberEntity();
  15. object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
  16. if (objArr != null && objArr.Length > 0)
  17. {
  18. DescriptionAttribute da = objArr[0] as DescriptionAttribute;
  19. m.Desction = da.Description;
  20. }
  21. m.EnumValue = Convert.ToInt32(e);
  22. m.EnumName = e.ToString();
  23. list.Add(m);
  24. }
  25. return list;
  26. }
  27. }
  28. public class EnumberEntity
  29. {
  30. /// <summary>
  31. /// 枚举的描述
  32. /// </summary>
  33. public string Desction { set; get; }
  34. /// <summary>
  35. /// 枚举名称
  36. /// </summary>
  37. public string EnumName { set; get; }
  38. /// <summary>
  39. /// 枚举对象的值
  40. /// </summary>
  41. public int EnumValue { set; get; }
  42. }
  43. }