2025-07-11 16:14:05 +08:00

46 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}