mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-17 15:06:34 +08:00
优化了示例工程
This commit is contained in:
@@ -4,6 +4,7 @@ using Serein.Library.Core.NodeFlow;
|
||||
using Serein.Library.Entity;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Tool;
|
||||
@@ -89,6 +90,9 @@ public static class MethodDetailsHelperTmp
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static ConcurrentDictionary<string, (object, MethodInfo)> ConvertorInstance =[];
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数信息
|
||||
/// </summary>
|
||||
@@ -100,36 +104,90 @@ public static class MethodDetailsHelperTmp
|
||||
return parameters.Select((it, index) =>
|
||||
{
|
||||
Type paremType;
|
||||
var attribute = it.GetCustomAttribute<EnumTypeConvertorAttribute>();
|
||||
if (attribute is not null)
|
||||
|
||||
if (it.GetCustomAttribute<EnumTypeConvertorAttribute>() is EnumTypeConvertorAttribute attribute1 && attribute1 is not null)
|
||||
{
|
||||
// 存在选择器
|
||||
paremType = attribute.EnumType;
|
||||
// 存在类型选择器
|
||||
paremType = attribute1.EnumType;
|
||||
return GetExplicitDataOfParameter(it, index, paremType, true);
|
||||
}
|
||||
else if (it.GetCustomAttribute<BindConvertorAttribute>() is BindConvertorAttribute attribute2 && attribute2 is not null)
|
||||
{
|
||||
paremType = attribute2.EnumType;
|
||||
|
||||
string key = typeof(IEnumConvertor<,>).FullName + attribute2.EnumType.FullName + attribute2.ConvertorType.FullName;
|
||||
|
||||
if (!ConvertorInstance.ContainsKey(key))
|
||||
{
|
||||
Type enumConvertorType = typeof(IEnumConvertor<,>);
|
||||
// 定义具体类型
|
||||
Type specificType = enumConvertorType.MakeGenericType(attribute2.EnumType, it.ParameterType);
|
||||
// 获取实现类的类型
|
||||
Type implementorType = attribute2.ConvertorType;
|
||||
// 创建实现类的实例
|
||||
object instance = Activator.CreateInstance(implementorType);
|
||||
// 调用 Convert 方法
|
||||
MethodInfo convertMethod = implementorType.GetMethod("Convertor");
|
||||
ConvertorInstance[key] = (instance, convertMethod);
|
||||
}
|
||||
|
||||
Func<object, object> func = (enumValue) =>
|
||||
{
|
||||
(var obj,var methodInfo) = ConvertorInstance[key];
|
||||
return methodInfo?.Invoke(obj, [enumValue]);
|
||||
};
|
||||
// 确保实例实现了所需接口
|
||||
ExplicitData ed = GetExplicitDataOfParameter(it, index, paremType, true, func);
|
||||
|
||||
return ed;
|
||||
}
|
||||
else
|
||||
{
|
||||
paremType = it.ParameterType;
|
||||
return GetExplicitDataOfParameter(it, index, it.ParameterType, it.HasDefaultValue);
|
||||
}
|
||||
string explicitTypeName = GetExplicitTypeName(paremType);
|
||||
var items = GetExplicitItems(paremType, explicitTypeName);
|
||||
if ("Bool".Equals(explicitTypeName)) explicitTypeName = "Select"; // 布尔值 转为 可选类型
|
||||
return new ExplicitData
|
||||
{
|
||||
IsExplicitData = attribute is null ? it.HasDefaultValue: true,
|
||||
Index = index,
|
||||
ExplicitTypeName = explicitTypeName,
|
||||
ExplicitType = paremType,
|
||||
DataType = it.ParameterType,
|
||||
ParameterName = it.Name,
|
||||
DataValue = it.HasDefaultValue ? it.DefaultValue.ToString() : "",
|
||||
Items = items.ToArray(),
|
||||
};
|
||||
|
||||
|
||||
|
||||
//string explicitTypeName = GetExplicitTypeName(paremType);
|
||||
//var items = GetExplicitItems(paremType, explicitTypeName);
|
||||
//if ("Bool".Equals(explicitTypeName)) explicitTypeName = "Select"; // 布尔值 转为 可选类型
|
||||
//return new ExplicitData
|
||||
//{
|
||||
// IsExplicitData = attribute is null ? it.HasDefaultValue: true,
|
||||
// Index = index,
|
||||
// ExplicitTypeName = explicitTypeName,
|
||||
// ExplicitType = paremType,
|
||||
// DataType = it.ParameterType,
|
||||
// ParameterName = it.Name,
|
||||
// DataValue = it.HasDefaultValue ? it?.DefaultValue?.ToString() : "",
|
||||
// Items = items.ToArray(),
|
||||
//};
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
private static ExplicitData GetExplicitDataOfParameter(ParameterInfo parameterInfo,
|
||||
int index,
|
||||
Type paremType,
|
||||
bool isExplicitData,
|
||||
Func<object, object> func = null)
|
||||
{
|
||||
|
||||
string explicitTypeName = GetExplicitTypeName(paremType);
|
||||
var items = GetExplicitItems(paremType, explicitTypeName);
|
||||
if ("Bool".Equals(explicitTypeName)) explicitTypeName = "Select"; // 布尔值 转为 可选类型
|
||||
return new ExplicitData
|
||||
{
|
||||
IsExplicitData = isExplicitData, //attribute is null ? parameterInfo.HasDefaultValue : true,
|
||||
Index = index,
|
||||
ExplicitTypeName = explicitTypeName,
|
||||
ExplicitType = paremType,
|
||||
Convertor = func,
|
||||
DataType = parameterInfo.ParameterType,
|
||||
ParameterName = parameterInfo.Name,
|
||||
DataValue = parameterInfo.HasDefaultValue ? parameterInfo?.DefaultValue?.ToString() : "",
|
||||
Items = items.ToArray(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断使用输入器还是选择器
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user