MonthEnum.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OASystem.Domain.Enums
  8. {
  9. /// <summary>
  10. /// 月份枚举
  11. /// </summary>
  12. public enum MonthEnum
  13. {
  14. /// <summary>
  15. /// 一月
  16. /// </summary>
  17. [Description("一月")]
  18. Jan = 1,
  19. /// <summary>
  20. /// 二月
  21. /// </summary>
  22. [Description("二月")]
  23. Feb,
  24. /// <summary>
  25. /// 三月
  26. /// </summary>
  27. [Description("三月")]
  28. Mar,
  29. /// <summary>
  30. /// 四月
  31. /// </summary>
  32. [Description("四月")]
  33. Apr,
  34. /// <summary>
  35. /// 五月
  36. /// </summary>
  37. [Description("五月")]
  38. May,
  39. /// <summary>
  40. /// 六月
  41. /// </summary>
  42. [Description("六月")]
  43. Jun,
  44. /// <summary>
  45. /// 七月
  46. /// </summary>
  47. [Description("七月")]
  48. Jul,
  49. /// <summary>
  50. /// 八月
  51. /// </summary>
  52. [Description("八月")]
  53. Aug,
  54. /// <summary>
  55. /// 九月
  56. /// </summary>
  57. [Description("九月")]
  58. Sep,
  59. /// <summary>
  60. /// 十月
  61. /// </summary>
  62. [Description("十月")]
  63. Oct,
  64. /// <summary>
  65. /// 十一月
  66. /// </summary>
  67. [Description("十一月")]
  68. Nov,
  69. /// <summary>
  70. /// 十二月
  71. /// </summary>
  72. [Description("十二月")]
  73. Dec,
  74. }
  75. static class EnumExtensions
  76. {
  77. public static string GetDescription(this Enum val)
  78. {
  79. var field = val.GetType().GetField(val.ToString());
  80. if (field != null)
  81. {
  82. var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
  83. return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
  84. }
  85. return string.Empty;
  86. }
  87. }
  88. }