LibEnum.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using YG.Lib;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml.Serialization;
  9. namespace YGUV.Lib
  10. {
  11. public static class LibEnum
  12. {
  13. /// <summary>
  14. /// 根据枚举的值获取枚举名称
  15. /// </summary>
  16. /// <typeparam name="T">枚举类型</typeparam>
  17. /// <param name="status">枚举的值</param>
  18. /// <returns></returns>
  19. public static string GetEnumName<T>(this int status)
  20. {
  21. return Enum.GetName(typeof(T), status);
  22. }
  23. /// <summary>
  24. /// 获取枚举名称集合
  25. /// </summary>
  26. /// <typeparam name="T"></typeparam>
  27. /// <returns></returns>
  28. public static string[] GetNamesArr<T>()
  29. {
  30. return Enum.GetNames(typeof(T));
  31. }
  32. /// <summary>
  33. /// 将枚举转换成字典集合
  34. /// </summary>
  35. /// <typeparam name="T">枚举类型</typeparam>
  36. /// <returns></returns>
  37. public static Dictionary<string, int> getEnumDic<T>()
  38. {
  39. Dictionary<string, int> resultList = new Dictionary<string, int>();
  40. Type type = typeof(T);
  41. var strList = GetNamesArr<T>().ToList();
  42. foreach (string key in strList)
  43. {
  44. string val = Enum.Format(type, Enum.Parse(type, key), "d");
  45. resultList.Add(key, int.Parse(val));
  46. }
  47. return resultList;
  48. }
  49. /// <summary>
  50. /// 将枚举转换成字典
  51. /// </summary>
  52. /// <typeparam name="TEnum"></typeparam>
  53. /// <returns></returns>
  54. public static Dictionary<string, int> GetDic<TEnum>()
  55. {
  56. Dictionary<string, int> dic = new Dictionary<string, int>();
  57. Type t = typeof(TEnum);
  58. var arr = Enum.GetValues(t);
  59. foreach (var item in arr)
  60. {
  61. dic.Add(item.ToString(), (int)item);
  62. }
  63. return dic;
  64. }
  65. }
  66. public enum ageinRunType
  67. {
  68. /// <summary>
  69. /// 准备
  70. /// </summary>
  71. Start,
  72. /// <summary>
  73. /// 执行中
  74. /// </summary>
  75. Runing,
  76. /// <summary>
  77. /// 结束
  78. /// </summary>
  79. End,
  80. }
  81. /// <summary>
  82. /// 测试项目类型
  83. /// </summary>
  84. public enum ageingType
  85. {
  86. /// <summary>
  87. /// 点灯
  88. /// </summary>
  89. Led,
  90. /// <summary>
  91. /// 电流
  92. /// </summary>
  93. Elect,
  94. /// <summary>
  95. /// 命令
  96. /// </summary>
  97. Set
  98. }
  99. }