MonthEnum.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
  81. return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
  82. }
  83. }
  84. }