using System.Reflection; using Kurisu.AspNetCore.Utils.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.EnumSetting; /// /// 枚举 /// [Authorize] [Route("api/[controller]")] [ApiController] public class EnumsController : ControllerBase { /// /// 获取所有枚举 /// /// 枚举code /// [HttpGet] public object GetEnums(string code) { var types = Assembly.Load("Dlhis.Entity") .GetTypes() .Where(x => x.IsEnum) .WhereIf(code.IsPresent(), x => x.Name == code); return types.Select(x => { var d = x.GetDescription(); return new { Code = x.Name, Name = d, Data = x.GetFields(BindingFlags.Public | BindingFlags.Static).Select(item => { var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); var fd = e.GetDescription(); return new { Key = fd, Value = (int)item.GetValue(null) }; }) }; }); } }