新增了对NodeaAction特性标记方法中,对params可变参数的支持

This commit is contained in:
fengjiayi
2024-11-02 22:11:38 +08:00
parent cd1642dcf7
commit 8b4ec31d83
15 changed files with 472 additions and 169 deletions

View File

@@ -1316,7 +1316,28 @@ namespace Serein.NodeFlow.Env
}
/// <summary>
/// 改变可选参数的数目
/// </summary>
/// <param name="nodeGuid">对应的节点Guid</param>
/// <param name="isAdd">true增加参数false减少参数</param>
/// <param name="paramIndex">以哪个参数为模板进行拷贝,或删去某个参数(该参数必须为可选参数)</param>
/// <returns></returns>
public async Task<bool> ChangeParameter(string nodeGuid, bool isAdd, int paramIndex)
{
var nodeModel = GuidToModel(nodeGuid);
if (nodeModel is null) return false;
bool isPass;
if (isAdd)
{
isPass = nodeModel.MethodDetails.AddParamsArg(paramIndex);
}
else
{
isPass = nodeModel.MethodDetails.RemoveParamsArg(paramIndex);
}
return isPass;
}
/// <summary>

View File

@@ -425,7 +425,17 @@ namespace Serein.NodeFlow.Env
}
/// <summary>
/// 改变可选参数的数目
/// </summary>
/// <param name="nodeGuid">对应的节点Guid</param>
/// <param name="isAdd">true增加参数false减少参数</param>
/// <param name="paramIndex">以哪个参数为模板进行拷贝,或删去某个参数(该参数必须为可选参数)</param>
/// <returns></returns>
public async Task<bool> ChangeParameter(string nodeGuid, bool isAdd, int paramIndex)
{
return await currentFlowEnvironment.ChangeParameter(nodeGuid, isAdd, paramIndex);
}
#region

View File

@@ -52,7 +52,7 @@ namespace Serein.NodeFlow.Env
{
methodDetails = new MethodDetails();
}
var md = methodDetails.CloneOfNode(nodeModel.Env, nodeModel);
var md = methodDetails.CloneOfNode(nodeModel);
nodeModel.DisplayName = md.MethodAnotherName;
nodeModel.MethodDetails = md;
nodeModel.OnCreating();

View File

@@ -819,6 +819,7 @@ namespace Serein.NodeFlow.Env
UIContextOperation?.Invoke(() => OnNodeLocated?.Invoke(new NodeLocatedEventArgs(nodeGuid)));
}
public async Task NotificationNodeValueChangeAsync(string nodeGuid, string path, object value)
{
if(IsLoadingProject || IsLoadingNode)
@@ -836,6 +837,18 @@ namespace Serein.NodeFlow.Env
}
/// <summary>
/// 改变可选参数的数目
/// </summary>
/// <param name="nodeGuid">对应的节点Guid</param>
/// <param name="isAdd">true增加参数false减少参数</param>
/// <param name="paramIndex">以哪个参数为模板进行拷贝,或删去某个参数(该参数必须为可选参数)</param>
/// <returns></returns>
public async Task<bool> ChangeParameter(string nodeGuid, bool isAdd, int paramIndex)
{
Console.WriteLine("远程环境尚未实现的接口ChangeParameter");
return false;
}
#region

View File

@@ -4,6 +4,7 @@ using Serein.Library;
using System.Collections.Concurrent;
using System.Reflection;
using Serein.Library.FlowNode;
using System.Diagnostics;
namespace Serein.NodeFlow.Tool;
@@ -31,8 +32,12 @@ public static class NodeMethodDetailsHelper
}
//var dllTypeName = $"{assemblyName}.{type.Name}";
var dllTypeMethodName = $"{assemblyName}.{type.Name}.{method.Name}";
Console.WriteLine("loading method : " +dllTypeMethodName);
Debug.WriteLine("loading method : " +dllTypeMethodName);
var explicitDataOfParameters = GetExplicitDataOfParameters(method.GetParameters());
//// 通过表达式树生成委托
//var methodDelegate = GenerateMethodDelegate(type, // 方法所在的对象类型
// method, // 方法信息
@@ -92,9 +97,13 @@ public static class NodeMethodDetailsHelper
var asyncPrefix = "[异步]"; // IsGenericTask(returnType) ? "[async]" : ;
var methodMethodAnotherName = isTask ? asyncPrefix + attribute.AnotherName : attribute.AnotherName;
bool hasParamsArg = false;
if (explicitDataOfParameters.Length > 0)
{
hasParamsArg = explicitDataOfParameters[^1].IsParams; // 取最后一个参数描述判断是否为params 入参
}
var md = new MethodDetails() // 从DLL生成方法描述
var md = new MethodDetails() // 从DLL生成方法描述元数据
{
ActingInstanceType = type,
// ActingInstance = instance,
@@ -104,6 +113,8 @@ public static class NodeMethodDetailsHelper
MethodAnotherName = methodMethodAnotherName,
ParameterDetailss = explicitDataOfParameters,
ReturnType = returnType,
// 如果存在可变参数,取最后一个元素的下标,否则为-1
ParamsArgIndex = hasParamsArg ? explicitDataOfParameters.Length-1 : -1,
};
var dd = new DelegateDetails(emitMethodType, methodDelegate) ;
return (md, dd);
@@ -144,16 +155,19 @@ public static class NodeMethodDetailsHelper
private static ParameterDetails[] GetExplicitDataOfParameters(ParameterInfo[] parameters)
{
return parameters.Select((it, index) =>
var tempParams = parameters.Select((it, index) =>
{
Type paremType;
if (it.GetCustomAttribute<EnumTypeConvertorAttribute>() is EnumTypeConvertorAttribute attribute1 && attribute1 is not null)
#region =>
if (it.GetCustomAttribute<EnumTypeConvertorAttribute>() is EnumTypeConvertorAttribute attribute1 && attribute1 is not null)
{
// 存在类型选择器
paremType = attribute1.EnumType;
return GetExplicitDataOfParameter(it, index, paremType, true);
return GetExplicitDataOfParameter(it, index, paremType, true); // “枚举=>类型”转换器 获取参数
}
#endregion
#region
else if (it.GetCustomAttribute<BindConvertorAttribute>() is BindConvertorAttribute attribute2 && attribute2 is not null)
{
paremType = attribute2.EnumType;
@@ -180,29 +194,22 @@ public static class NodeMethodDetailsHelper
return methodInfo?.Invoke(obj, [enumValue]);
}
// 确保实例实现了所需接口
ParameterDetails ed = GetExplicitDataOfParameter(it, index, paremType, true, func);
ParameterDetails ed = GetExplicitDataOfParameter(it, index, paremType, true, func); // 自定义的转换器 获取参数
return ed;
}
#endregion
#region
else
{
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(),
//};
var tmp = GetExplicitDataOfParameter(it, index, it.ParameterType, it.HasDefaultValue); // 常规方法的获取参数
return tmp;
}
#endregion
}).ToArray();
return tempParams;
}
private static ParameterDetails GetExplicitDataOfParameter(ParameterInfo parameterInfo,
@@ -213,7 +220,6 @@ public static class NodeMethodDetailsHelper
{
bool hasParams = parameterInfo.IsDefined(typeof(ParamArrayAttribute)); // 判断是否为可变参数
string explicitTypeName = GetExplicitTypeName(paremType);
var items = GetExplicitItems(paremType, explicitTypeName);
if ("Bool".Equals(explicitTypeName)) explicitTypeName = "Select"; // 布尔值 转为 可选类型