EnumUtils.cs 618 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace COSXML.Utils
  5. {
  6. public static class EnumUtils
  7. {
  8. public static string GetValue(Enum value)
  9. {
  10. if (value == null)
  11. {
  12. return null;
  13. }
  14. string name = value.ToString();
  15. var fieldInfo = value.GetType().GetField(name);
  16. var attributes = fieldInfo.GetCustomAttributes(typeof(CosValueAttribute), false);
  17. return attributes != null && attributes.Length > 0 ? ((CosValueAttribute)attributes[0]).Value : name;
  18. }
  19. }
  20. }