123456789101112131415161718192021222324252627282930313233343536 |
- using EnumsNET;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SMP.Common.Enum
- {
- public static class EnumHelper
- {
- public static IEnumerable<EnumItem> GetEnumModels(string assambly, string typeName)
- {
- string fuleName = $"{typeName},{assambly}";
- Type type = Type.GetType(fuleName, false);
- if (type == null)
- return null;
- var members = Enums.GetMembers(type, EnumMemberSelection.All);
- if (members != null)
- {
- var result = members.Select(i => new EnumItem { Name = i.Name, Value = i.ToInt32(), Desc = i.AsString(EnumFormat.Description) });
- return result;
- }
- else return null;
- }
- }
- public class EnumItem
- {
- public int? Value { get; set; }
- public string Name { get; set; }
- public string Desc { get; set; }
- }
- }
|