50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Reflection;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Dlhis.Common.EnumSetting;
|
|
|
|
/// <summary>
|
|
/// 枚举
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class EnumsController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// 获取所有枚举
|
|
/// </summary>
|
|
/// <param name="code">枚举code</param>
|
|
/// <returns></returns>
|
|
[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)
|
|
};
|
|
})
|
|
};
|
|
});
|
|
}
|
|
}
|