46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using JiShe.IoT.CommonServices.Dto;
|
||
using JiShe.ServicePro.Commons;
|
||
using JiShe.ServicePro.Core;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using static FreeSql.Internal.GlobalFilter;
|
||
|
||
namespace JiShe.IoT.CommonServices
|
||
{
|
||
public class CommonService : IoTAppService, ICommonService
|
||
{
|
||
private static ConcurrentDictionary<string, List<SelectResult>> _selectListType = new();
|
||
|
||
/// <summary>
|
||
/// 初始化所有固定的枚举下拉框字典
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public void InitSelectTypetList()
|
||
{
|
||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||
var typeList = assemblies.SelectMany(x => x.GetTypes()).Where(x => x.IsDefined(typeof(SelectResultAttribute), false));
|
||
|
||
foreach (var typeInfoItem in typeList)
|
||
{
|
||
SelectResultAttribute[] selectResultAttribute =
|
||
(SelectResultAttribute[])typeInfoItem.GetCustomAttributes(typeof(SelectResultAttribute), false);
|
||
|
||
_selectListType.TryAdd(typeInfoItem.Name, CommonHelper.GetTypeAttributeList(typeInfoItem, selectResultAttribute[0].IsGetPropertie));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据type名称获取下拉框数据,主要是枚举等
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
public List<SelectResult> GetSelectResultList(SelectResultListInput input)
|
||
{
|
||
List<SelectResult> selectResults = _selectListType.TryGetValue(input.TypeName, out var list) ? list : new List<SelectResult>();
|
||
|
||
return selectResults;
|
||
}
|
||
}
|
||
}
|