mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-21 15:26:34 +08:00
更新了代码生成器的生成逻辑。
修复了Emit对于集合类型创建委托时,类型指定Bug。
This commit is contained in:
@@ -99,10 +99,6 @@ namespace Serein.Library.Api
|
|||||||
/// 节点创建时的行为
|
/// 节点创建时的行为
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void OnCreating();
|
void OnCreating();
|
||||||
/*/// <summary>
|
|
||||||
/// 节点移除时的行为
|
|
||||||
/// </summary>
|
|
||||||
void Remove();*/
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 节点保存时如若需要保存自定义数据,可通过该方法进行控制保存逻辑
|
/// 节点保存时如若需要保存自定义数据,可通过该方法进行控制保存逻辑
|
||||||
|
|||||||
@@ -197,9 +197,8 @@ namespace Serein.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectPool<Stack<IFlowNode>> flowStackPool = new ObjectPool<Stack<IFlowNode>>(()=> new Stack<IFlowNode>());
|
private readonly static ObjectPool<Stack<IFlowNode>> flowStackPool = new ObjectPool<Stack<IFlowNode>>(()=> new Stack<IFlowNode>());
|
||||||
//private static ObjectPool<HashSet<IFlowNode>> processedNodesPool = new ObjectPool<HashSet<IFlowNode>>(()=> new HashSet<IFlowNode>());
|
private readonly static ObjectPool<HashSet<IFlowNode>> checkpoints = new ObjectPool<HashSet<IFlowNode>>(()=> new HashSet<IFlowNode>());
|
||||||
private static ObjectPool<HashSet<IFlowNode>> checkpoints = new ObjectPool<HashSet<IFlowNode>>(()=> new HashSet<IFlowNode>());
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 开始执行
|
/// 开始执行
|
||||||
|
|||||||
@@ -154,13 +154,13 @@ namespace Serein.Library
|
|||||||
{
|
{
|
||||||
if (emitType == EmitType.CollectionSetter)
|
if (emitType == EmitType.CollectionSetter)
|
||||||
{
|
{
|
||||||
emitType = EmitType.CollectionSetter;
|
this.emitType = EmitType.CollectionSetter;
|
||||||
collectionSetter = EmitHelper.CreateCollectionSetter(type);
|
collectionSetter = EmitHelper.CreateCollectionSetter(type);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (emitType == EmitType.CollectionGetter)
|
else if (emitType == EmitType.CollectionGetter)
|
||||||
{
|
{
|
||||||
emitType = EmitType.CollectionGetter;
|
this.emitType = EmitType.CollectionGetter;
|
||||||
collectionGetter = EmitHelper.CreateCollectionGetter(type);
|
collectionGetter = EmitHelper.CreateCollectionGetter(type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Serein.Library.Api;
|
using Serein.Library.Api;
|
||||||
using Serein.Library.Utils;
|
using Serein.Library.Utils;
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -145,6 +146,8 @@ namespace Serein.Library
|
|||||||
this.Name = pdInfo.ArgName;
|
this.Name = pdInfo.ArgName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过参数信息加载实体,用于加载项目文件、远程连接的场景
|
/// 通过参数信息加载实体,用于加载项目文件、远程连接的场景
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -160,6 +163,15 @@ namespace Serein.Library
|
|||||||
IsParams = info.IsParams;
|
IsParams = info.IsParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
partial void OnIsExplicitDataChanged(bool oldValue, bool newValue)
|
||||||
|
{
|
||||||
|
if(DataType == typeof(IFlowContext))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转为描述
|
/// 转为描述
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -209,9 +221,9 @@ namespace Serein.Library
|
|||||||
return data;
|
return data;
|
||||||
|
|
||||||
// 2. 特定快捷类型
|
// 2. 特定快捷类型
|
||||||
if (typeof(IFlowEnvironment).IsAssignableFrom(DataType)) return NodeModel.Env;
|
|
||||||
if (typeof(IFlowContext).IsAssignableFrom(DataType)) return context;
|
if (typeof(IFlowContext).IsAssignableFrom(DataType)) return context;
|
||||||
if (typeof(IFlowNode).IsAssignableFrom(DataType)) return NodeModel;
|
//if (typeof(IFlowEnvironment).IsAssignableFrom(DataType)) return NodeModel.Env;
|
||||||
|
//if (typeof(IFlowNode).IsAssignableFrom(DataType)) return NodeModel;
|
||||||
|
|
||||||
// 3. 显式常量参数
|
// 3. 显式常量参数
|
||||||
if (IsExplicitData && !DataValue.StartsWith("@", StringComparison.OrdinalIgnoreCase))
|
if (IsExplicitData && !DataValue.StartsWith("@", StringComparison.OrdinalIgnoreCase))
|
||||||
@@ -224,7 +236,15 @@ namespace Serein.Library
|
|||||||
if (ArgDataSourceType == ConnectionArgSourceType.GetPreviousNodeData)
|
if (ArgDataSourceType == ConnectionArgSourceType.GetPreviousNodeData)
|
||||||
{
|
{
|
||||||
var prevNodeGuid = context.GetPreviousNode(NodeModel.Guid);
|
var prevNodeGuid = context.GetPreviousNode(NodeModel.Guid);
|
||||||
inputParameter = prevNodeGuid != null ? context.GetFlowData(prevNodeGuid)?.Value : null;
|
if(prevNodeGuid is null)
|
||||||
|
{
|
||||||
|
inputParameter = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var prevNodeData = context.GetFlowData(prevNodeGuid);
|
||||||
|
inputParameter = prevNodeData.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,16 +69,18 @@ namespace Serein.Library
|
|||||||
/// 是否禁止参数进行修改(初始化后不能再通过 Setter 修改)
|
/// 是否禁止参数进行修改(初始化后不能再通过 Setter 修改)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsProtection = false;
|
public bool IsProtection = false;
|
||||||
|
/*
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义代码(属性变更前)
|
/// 自定义代码(属性变更前)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("此属性已经过时,可能在下一个版本中移除", false)]
|
||||||
public string CustomCodeAtStart = null;
|
public string CustomCodeAtStart = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义代码(属性变更后)
|
/// 自定义代码(属性变更后)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string CustomCodeAtEnd = null;
|
[Obsolete("此属性已经过时,可能在下一个版本中移除", false)]
|
||||||
|
public string CustomCodeAtEnd = null;*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ using System.Threading;
|
|||||||
namespace Serein.Library.NodeGenerator
|
namespace Serein.Library.NodeGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 一个增量源生成器,用于为带有自定义 MyClassAttribute 特性的类中的字段生成带有自定义 set 行为的属性。
|
/// 一个增量源生成器,用于为带有自定义 MyClassAttribute 特性的类中的字段生成带有自定义 set 行为的属性。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -33,7 +32,7 @@ namespace Serein.Library.NodeGenerator
|
|||||||
/*
|
/*
|
||||||
CreateSyntaxProvider : 第一个参数用于筛选特定语法节点,第二个参数则用于转换筛选出来的节点。
|
CreateSyntaxProvider : 第一个参数用于筛选特定语法节点,第二个参数则用于转换筛选出来的节点。
|
||||||
SemanticModel : 通过 语义模型 (SemanticModel) 来解析代码中的符号信息,获取类、方法、属性等更具体的类型和特性信息。例如某个特性属于哪个类型。
|
SemanticModel : 通过 语义模型 (SemanticModel) 来解析代码中的符号信息,获取类、方法、属性等更具体的类型和特性信息。例如某个特性属于哪个类型。
|
||||||
AddSource : 生成器的最终目标是生成代码。使用 AddSource 将生成的代码以字符串形式注入到编译过程当中。通常会通过字符串拼接或 StringBuilder 来构建生成的 C# 代码。
|
AddSource : 生成器的最终目标是生成代码。使用 AddSource 将生成的代码以字符串形式注入到编译过程当中。
|
||||||
*/
|
*/
|
||||||
// 通过 SyntaxProvider 查找所有带有任意特性修饰的类声明语法节点
|
// 通过 SyntaxProvider 查找所有带有任意特性修饰的类声明语法节点
|
||||||
var classDeclarations = context.SyntaxProvider
|
var classDeclarations = context.SyntaxProvider
|
||||||
@@ -87,19 +86,6 @@ namespace Serein.Library.NodeGenerator
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private int myProperty;
|
|
||||||
|
|
||||||
public int MyProperty { get => myProperty; set
|
|
||||||
{
|
|
||||||
if(myProperty == null)
|
|
||||||
{
|
|
||||||
|
|
||||||
myProperty = value;
|
|
||||||
}
|
|
||||||
} }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 为给定的类生成带有自定义 set 行为的属性。
|
/// 为给定的类生成带有自定义 set 行为的属性。
|
||||||
@@ -163,6 +149,11 @@ namespace Serein.Library.NodeGenerator
|
|||||||
//sb.AppendLine(leadingTrivia);
|
//sb.AppendLine(leadingTrivia);
|
||||||
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} oldValue, {fieldType} newValue);");
|
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} oldValue, {fieldType} newValue);");
|
||||||
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} value);");
|
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} value);");
|
||||||
|
if (isProtection)
|
||||||
|
{
|
||||||
|
sb.AppendLine($" private bool __{propertyName}ProtectionField = false;");
|
||||||
|
}
|
||||||
|
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
// 生成 getter / setter
|
// 生成 getter / setter
|
||||||
sb.AppendLine($" /// <inheritdoc cref=\"{fieldName}\"/>");
|
sb.AppendLine($" /// <inheritdoc cref=\"{fieldName}\"/>");
|
||||||
@@ -172,10 +163,22 @@ namespace Serein.Library.NodeGenerator
|
|||||||
sb.AppendLine($" get => {fieldName};"); // getter方法
|
sb.AppendLine($" get => {fieldName};"); // getter方法
|
||||||
sb.AppendLine( " set");
|
sb.AppendLine( " set");
|
||||||
sb.AppendLine( " {");
|
sb.AppendLine( " {");
|
||||||
sb.AppendLine($" if ({fieldName} {(isProtection ? "== default" : "!= value")})"); // 非保护的Setter
|
//sb.AppendLine($" if ({fieldName} {(isProtection ? "== default" : "!= value")})"); // 非保护的Setter
|
||||||
sb.AppendLine( " {");
|
|
||||||
sb.AppendLine($" var __oldValue = {fieldName};");
|
sb.AppendLine($" var __oldValue = {fieldName};");
|
||||||
sb.AppendLine($" SetProperty<{fieldType}>(ref {fieldName}, value); // 通知UI属性发生改变了");
|
if (isProtection)
|
||||||
|
{
|
||||||
|
sb.AppendLine($" if (!__{propertyName}ProtectionField && SetProperty<{fieldType}>(ref {fieldName}, value))"); // 非保护的Setter
|
||||||
|
sb.AppendLine($" {{");
|
||||||
|
sb.AppendLine($" __{propertyName}ProtectionField = true;");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.AppendLine($" if (SetProperty<{fieldType}>(ref {fieldName}, value))"); // 非保护的Setter
|
||||||
|
sb.AppendLine($" {{");
|
||||||
|
}
|
||||||
|
|
||||||
|
//sb.AppendLine($" SetProperty<{fieldType}>(ref {fieldName}, value); ");
|
||||||
sb.AppendLine($" On{propertyName}Changed(value);");
|
sb.AppendLine($" On{propertyName}Changed(value);");
|
||||||
sb.AppendLine($" On{propertyName}Changed(__oldValue, value);");
|
sb.AppendLine($" On{propertyName}Changed(__oldValue, value);");
|
||||||
if (attributeInfo.Search(nameof(PropertyInfo), nameof(PropertyInfo.IsPrint), value => bool.Parse(value)))
|
if (attributeInfo.Search(nameof(PropertyInfo), nameof(PropertyInfo.IsPrint), value => bool.Parse(value)))
|
||||||
@@ -240,21 +243,22 @@ namespace Serein.Library.NodeGenerator
|
|||||||
sb.AppendLine(" /// </summary>");
|
sb.AppendLine(" /// </summary>");
|
||||||
sb.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
|
sb.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
|
||||||
|
|
||||||
sb.AppendLine(" protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) ");
|
sb.AppendLine(" protected bool SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) ");
|
||||||
sb.AppendLine(" { ");
|
sb.AppendLine(" { ");
|
||||||
sb.AppendLine(" //if (Equals(storage, value)) ");
|
sb.AppendLine(" if (Equals(storage, value)) ");
|
||||||
sb.AppendLine(" //{ ");
|
sb.AppendLine(" { ");
|
||||||
sb.AppendLine(" // return; ");
|
sb.AppendLine(" return false; ");
|
||||||
sb.AppendLine(" //} ");
|
sb.AppendLine(" } ");
|
||||||
sb.AppendLine(" ");
|
sb.AppendLine(" ");
|
||||||
sb.AppendLine(" storage = value; ");
|
sb.AppendLine(" storage = value; ");
|
||||||
sb.AppendLine(" PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); ");
|
sb.AppendLine(" PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); ");
|
||||||
|
sb.AppendLine(" return true; ");
|
||||||
sb.AppendLine(" } ");
|
sb.AppendLine(" } ");
|
||||||
|
|
||||||
sb.AppendLine(" public void OnPropertyChanged(string propertyName) => ");
|
sb.AppendLine(" public void OnPropertyChanged(string propertyName) => ");
|
||||||
sb.AppendLine(" PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); ");
|
sb.AppendLine(" PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); ");
|
||||||
|
sb.AppendLine(" ");
|
||||||
sb.AppendLine(" ");
|
sb.AppendLine(" ");
|
||||||
sb.AppendLine(" ");
|
|
||||||
sb.AppendLine(" ");
|
sb.AppendLine(" ");
|
||||||
|
|
||||||
// 生成变量修改
|
// 生成变量修改
|
||||||
|
|||||||
Reference in New Issue
Block a user