AttributeHelper.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace CP.Common
  7. {
  8. public static class AttributeHelper
  9. {
  10. /// <summary>
  11. /// 获取彩种对应编码
  12. /// </summary>
  13. /// <param name="value">彩种枚举类型</param>
  14. /// <returns></returns>
  15. public static string GetAttributeText(Enum value)
  16. {
  17. if (value == null)
  18. {
  19. throw new ArgumentException("value");
  20. }
  21. string code = value.ToString();
  22. var fieldInfo = value.GetType().GetField(code);
  23. return ((TextAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TextAttribute))).Text;
  24. }
  25. }
  26. /// <summary>
  27. /// 父节点
  28. /// </summary>
  29. public class ParentAttribute : Attribute
  30. {
  31. private int parent;
  32. public ParentAttribute(int value)
  33. {
  34. parent = value;
  35. }
  36. public int Parent
  37. {
  38. get
  39. {
  40. return parent;
  41. }
  42. }
  43. }
  44. public class ImgAttribute : Attribute
  45. {
  46. private string img;
  47. public ImgAttribute(string value)
  48. {
  49. img = value;
  50. }
  51. public string Img
  52. {
  53. get
  54. {
  55. return img;
  56. }
  57. }
  58. }
  59. public class TextAttribute : Attribute
  60. {
  61. private string text;
  62. public TextAttribute(string value)
  63. {
  64. this.text = value;
  65. }
  66. public string Text
  67. {
  68. get
  69. {
  70. return text;
  71. }
  72. }
  73. }
  74. }