mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-05 07:46:35 +08:00
增加流程运行特性:支持异步节点
This commit is contained in:
@@ -146,9 +146,26 @@ namespace Serein.NodeFlow.Tool
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), methodInfo);
|
||||
var lambda = Expression.Lambda(Expression.Convert(methodCall, typeof(object)), parameter);
|
||||
// Func<object, object>
|
||||
return lambda.Compile();
|
||||
|
||||
if(MethodDetailsHelperTmp.IsGenericTask(methodInfo.ReturnType,out var taskResult))
|
||||
{
|
||||
if(taskResult is null)
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, Task>>(Expression.Convert(methodCall, typeof(Task)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, Task<object>>>(Expression.Convert(methodCall, typeof(Task<object>)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object>>(Expression.Convert(methodCall, typeof(object)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -262,14 +279,29 @@ namespace Serein.NodeFlow.Tool
|
||||
convertedArgs
|
||||
);
|
||||
|
||||
// 创建 lambda 表达式
|
||||
var lambda = Expression.Lambda<Func<object, object[], object>>(
|
||||
Expression.Convert(methodCall, typeof(object)),
|
||||
instanceParam,
|
||||
argsParam
|
||||
);
|
||||
//var resule = task.DynamicInvoke((object)[Activator.CreateInstance(type), [new DynamicContext(null)]]);
|
||||
return lambda.Compile();
|
||||
if (MethodDetailsHelperTmp.IsGenericTask(methodInfo.ReturnType, out var taskResult))
|
||||
{
|
||||
if (taskResult is null)
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], Task>>
|
||||
(Expression.Convert(methodCall, typeof(Task)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], Task<object>>>
|
||||
(Expression.Convert(methodCall, typeof(Task<object>)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], object>>
|
||||
(Expression.Convert(methodCall, typeof(object)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public static class MethodDetailsHelperTmp
|
||||
method.ReturnType);// 返回值
|
||||
|
||||
|
||||
Type returnType;
|
||||
Type? returnType;
|
||||
bool isTask = IsGenericTask(method.ReturnType, out var taskResult);
|
||||
|
||||
if (attribute.MethodDynamicType == Library.Enums.NodeType.Flipflop)
|
||||
@@ -85,7 +85,7 @@ public static class MethodDetailsHelperTmp
|
||||
}
|
||||
else if(isTask)
|
||||
{
|
||||
returnType = taskResult;
|
||||
returnType = taskResult is null ? typeof(Task) : taskResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,12 +119,12 @@ public static class MethodDetailsHelperTmp
|
||||
|
||||
}
|
||||
|
||||
public static bool IsGenericTask(Type returnType, out Type taskResult)
|
||||
public static bool IsGenericTask(Type returnType, out Type? taskResult)
|
||||
{
|
||||
// 判断是否为 Task 类型或泛型 Task<T>
|
||||
if (returnType == typeof(Task))
|
||||
{
|
||||
taskResult = returnType;
|
||||
taskResult = null;
|
||||
return true;
|
||||
}
|
||||
else if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>))
|
||||
|
||||
Reference in New Issue
Block a user