EnumHelper.cs 1001 B

123456789101112131415161718192021222324252627282930313233343536
  1. using EnumsNET;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace SMP.Common.Enum
  8. {
  9. public static class EnumHelper
  10. {
  11. public static IEnumerable<EnumItem> GetEnumModels(string assambly, string typeName)
  12. {
  13. string fuleName = $"{typeName},{assambly}";
  14. Type type = Type.GetType(fuleName, false);
  15. if (type == null)
  16. return null;
  17. var members = Enums.GetMembers(type, EnumMemberSelection.All);
  18. if (members != null)
  19. {
  20. var result = members.Select(i => new EnumItem { Name = i.Name, Value = i.ToInt32(), Desc = i.AsString(EnumFormat.Description) });
  21. return result;
  22. }
  23. else return null;
  24. }
  25. }
  26. public class EnumItem
  27. {
  28. public int? Value { get; set; }
  29. public string Name { get; set; }
  30. public string Desc { get; set; }
  31. }
  32. }