init 项目代码初始化
This commit is contained in:
49
Src/Dlhis.Common/EnumSetting/EnumsController.cs
Normal file
49
Src/Dlhis.Common/EnumSetting/EnumsController.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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)
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user