1. 重新设计了Generate项目及相关特性的命名,避免与其他类型混淆。

2. 补充了部分注释。
3. 修改了删除容器节点时,容器内子节点未正确删除的问题。
This commit is contained in:
fengjiayi
2025-07-30 21:15:07 +08:00
parent 93148b11a5
commit 152077e9b5
188 changed files with 2713 additions and 1406 deletions

View File

@@ -17,11 +17,22 @@ namespace Serein.NodeFlow.Tool
private AssemblyLoadContext context;
private Dictionary<string, Type> dicTypes = new Dictionary<string, Type>();
/// <summary>
/// 程序集加载器构造函数
/// </summary>
/// <param name="basePath"></param>
public AssemblyLoader(string basePath)
{
_basePath = basePath;
}
/// <summary>
/// 加载指定的类型
/// </summary>
/// <param name="dllFileName"></param>
/// <param name="typeName"></param>
/// <returns></returns>
public Type Load(string dllFileName, string typeName)
{
context = new AssemblyLoadContext(dllFileName);

View File

@@ -12,6 +12,9 @@ namespace Serein.NodeFlow.Tool
{
private readonly HashSet<MetadataReference> _references = new HashSet<MetadataReference>();
/// <summary>
/// 构造一个新的动态编译器实例。
/// </summary>
public DynamicCompiler()
{
// 默认添加当前 AppDomain 加载的所有程序集
@@ -110,10 +113,6 @@ namespace Serein.NodeFlow.Tool
}
public void Save()
{
}

View File

@@ -33,7 +33,11 @@ namespace Serein.NodeFlow.Tool
/// </summary>
public override Encoding Encoding => Encoding.UTF8;
/// <summary>
/// 重写Write方法处理单个字符的写入
/// </summary>
/// <param name="value"></param>
public override void Write(char value)
{
stringWriter.Write(value);
@@ -43,6 +47,10 @@ namespace Serein.NodeFlow.Tool
}
}
/// <summary>
/// 重写Write方法处理字符串的写入
/// </summary>
/// <param name="value"></param>
public override void Write(string? value)
{
if (string.IsNullOrWhiteSpace(value)) return;
@@ -53,6 +61,10 @@ namespace Serein.NodeFlow.Tool
}
}
/// <summary>
/// 重写WriteLine方法处理字符串的换行写入
/// </summary>
/// <param name="value"></param>
public override void WriteLine(string? value)
{
if (string.IsNullOrWhiteSpace(value)) return;

View File

@@ -103,8 +103,7 @@ namespace Serein.NodeFlow.Tool
/// <summary>
/// 加载Windows类库
/// </summary>
/// <param name="path"></param>
/// <param name="isRecurrence">是否递归加载</param>
/// <param name="file"></param>
private static bool LoadWindowsLibrarie(string file)
{
IntPtr hModule = IntPtr.Zero;

View File

@@ -1,5 +1,6 @@
using Serein.Library;
using Serein.Library.Api;
using Serein.Library.Utils;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
@@ -7,6 +8,9 @@ using System.Reflection;
namespace Serein.NodeFlow.Tool;
/// <summary>
/// 节点方法描述帮助类
/// </summary>
public static class NodeMethodDetailsHelper
{
@@ -25,15 +29,16 @@ public static class NodeMethodDetailsHelper
/// <param name="type">方法所属的类型</param>
/// <param name="methodInfo">方法信息</param>
/// <param name="assemblyName">方法所属的程序集名称</param>
/// <param name="outMethodInfo">传出的方法信息</param>
/// <param name="methodDetails">创建的方法描述,用来生成节点信息</param>
/// <param name="delegateDetails">方法对应的Emit动态委托</param>
/// <returns>指示是否创建成功</returns>
public static bool TryCreateDetails(Type type,
MethodInfo methodInfo,
string assemblyName,
[MaybeNullWhen(false)] out MethodInfo outMethodInfo,
[MaybeNullWhen(false)] out MethodDetails methodDetails,
[MaybeNullWhen(false)] out DelegateDetails delegateDetails)
[NotNullWhen(true)] out MethodInfo? outMethodInfo,
[NotNullWhen(true)] out MethodDetails? methodDetails,
[NotNullWhen(true)] out DelegateDetails? delegateDetails)
{
@@ -60,7 +65,7 @@ public static class NodeMethodDetailsHelper
Type? returnType;
bool isAsync = IsGenericTask(methodInfo.ReturnType, out var taskResult);
bool isAsync = EmitHelper.IsGenericTask(methodInfo.ReturnType, out var taskResult);
bool isStatic = methodInfo.IsStatic;
@@ -172,6 +177,12 @@ public static class NodeMethodDetailsHelper
return true;
}
/// <summary>
/// 获取方法签名
/// </summary>
/// <param name="method"></param>
/// <returns></returns>
public static string GetMethodSignature(MethodInfo method)
{
if (method == null) return string.Empty;
@@ -184,28 +195,8 @@ public static class NodeMethodDetailsHelper
return $"{methodName}({parameters})";
//return $"{methodName}({parameters}) : {returnType}";
}
public static bool IsGenericTask(Type returnType, out Type? taskResult)
{
// 判断是否为 Task 类型或泛型 Task<T>
if (returnType == typeof(Task))
{
taskResult = null;
return true;
}
else if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>))
{
// 获取泛型参数类型
Type genericArgument = returnType.GetGenericArguments()[0];
taskResult = genericArgument;
return true;
}
else
{
taskResult = null;
return false;
}
}
private static ConcurrentDictionary<string, (object, MethodInfo)> ConvertorInstance =[];
@@ -231,6 +222,7 @@ public static class NodeMethodDetailsHelper
}
#endregion
#region
#if false
else if (it.GetCustomAttribute<BindConvertorAttribute>() is BindConvertorAttribute attribute2 && attribute2 is not null)
{
paremType = attribute2.EnumType;
@@ -262,6 +254,8 @@ public static class NodeMethodDetailsHelper
return ed;
}
#endif
#endregion
#region
else

View File

@@ -7,11 +7,20 @@ using System.Reflection.Emit;
namespace Serein.NodeFlow.Tool
{
/// <summary>
/// 动态创建对象的帮助类,支持根据属性字典创建对象并设置属性值。
/// </summary>
public class ObjDynamicCreateHelper
{
// 类型缓存,键为类型的唯一名称(可以根据实际需求调整生成方式)
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
/// <summary>
/// 根据属性字典和类型名称创建对象实例,并设置属性值。
/// </summary>
/// <param name="properties"></param>
/// <param name="typeName"></param>
/// <returns></returns>
public static object Resolve(Dictionary<string, object> properties, string typeName)
{
var obj = CreateObjectWithProperties(properties, typeName);