From 34939cd34c0bedded9968622405353f677a1e73b Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Mon, 4 Aug 2025 14:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Serein.Library.csproj | 2 +- Library/Utils/TypeHelper.cs | 24 ++++++-- NodeFlow/Serein.NodeFlow.csproj | 2 +- .../Serein.Extend.NewtonsoftJson.csproj | 2 +- .../Serein.Library.NodeGenerator.csproj | 2 +- .../Serein.Proto.WebSocket.csproj | 2 +- Serein.Script/Serein.Script.csproj | 2 +- Serein.Script/SereinScriptToCsharpScript.cs | 60 ++++++++++++++++--- Workbench/Serein.WorkBench.csproj | 1 + 9 files changed, 77 insertions(+), 20 deletions(-) diff --git a/Library/Serein.Library.csproj b/Library/Serein.Library.csproj index 33995fb..96328fd 100644 --- a/Library/Serein.Library.csproj +++ b/Library/Serein.Library.csproj @@ -2,7 +2,7 @@ SereinFow - 1.2.3 + 1.2.4 动态节点流、可视化编辑的基本依赖,支持导入C# DLL生成自定义节点,提供二次开发支持,适合用于可视化编程和流程设计 README.md https://github.com/fhhyyp/serein-flow diff --git a/Library/Utils/TypeHelper.cs b/Library/Utils/TypeHelper.cs index 42c326d..20f1fae 100644 --- a/Library/Utils/TypeHelper.cs +++ b/Library/Utils/TypeHelper.cs @@ -12,8 +12,13 @@ namespace Serein.Library.Utils public static class TypeHelper { - - public static string GetFriendlyName(this Type type,bool isFullName = true) + /// + /// 对于泛型类型以友好格式显示其文本值 + /// + /// + /// + /// + public static string GetFriendlyName(this Type type, bool isFullName = true) { if (type.IsGenericType) { @@ -45,11 +50,20 @@ namespace Serein.Library.Utils } else { - return TypeMap.TryGetValue(type, out var alias) ? alias : isFullName ? type.FullName : type.Name; ; + + if (isFullName) + { + return type.FullName; + } + else + { + return type.Name; + } + //return TypeMap.TryGetValue(type, out var alias) ? alias : isFullName ? type.FullName : type.Name; ; } } - private static readonly Dictionary TypeMap = new Dictionary + /*private static readonly Dictionary TypeMap = new Dictionary { [typeof(int)] = "int", [typeof(string)] = "string", @@ -67,7 +81,7 @@ namespace Serein.Library.Utils [typeof(ulong)] = "ulong", [typeof(ushort)] = "ushort", [typeof(sbyte)] = "sbyte", - }; + };*/ /// diff --git a/NodeFlow/Serein.NodeFlow.csproj b/NodeFlow/Serein.NodeFlow.csproj index 2be26fe..7011358 100644 --- a/NodeFlow/Serein.NodeFlow.csproj +++ b/NodeFlow/Serein.NodeFlow.csproj @@ -1,7 +1,7 @@  - 1.2.3 + 1.2.4 net8.0 enable enable diff --git a/Serein.Extend.NewtonsoftJson/Serein.Extend.NewtonsoftJson.csproj b/Serein.Extend.NewtonsoftJson/Serein.Extend.NewtonsoftJson.csproj index 71f83eb..84a8f89 100644 --- a/Serein.Extend.NewtonsoftJson/Serein.Extend.NewtonsoftJson.csproj +++ b/Serein.Extend.NewtonsoftJson/Serein.Extend.NewtonsoftJson.csproj @@ -8,7 +8,7 @@ ..\.\.Output 为 SereinFlow 提供的 JSON 扩展 - 1.0.0 + 1.0.1 通过 NewtonsoftJson 实现JSON门户扩展,用于解决 Serein.Proto.* 项目下需要 JSON 序列化与反序列化的场景 MIT True diff --git a/Serein.Library.MyGenerator/Serein.Library.NodeGenerator.csproj b/Serein.Library.MyGenerator/Serein.Library.NodeGenerator.csproj index 5d42f45..e38fc83 100644 --- a/Serein.Library.MyGenerator/Serein.Library.NodeGenerator.csproj +++ b/Serein.Library.MyGenerator/Serein.Library.NodeGenerator.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 1.2.3 + 1.2.4 false ..\.\.Output diff --git a/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj b/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj index 14c48d3..18dee7d 100644 --- a/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj +++ b/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj @@ -8,7 +8,7 @@ ..\.\.Output 基于Json数据载体的WebSocket交互工具包 - 1.0.0 + 1.0.1 基于Json数据载体的WebSocket交互工具包 MIT True diff --git a/Serein.Script/Serein.Script.csproj b/Serein.Script/Serein.Script.csproj index 546ff30..c4c2ac7 100644 --- a/Serein.Script/Serein.Script.csproj +++ b/Serein.Script/Serein.Script.csproj @@ -7,7 +7,7 @@ ..\.\.Output 基于AST实现的脚本语言 - 1.0.0 + 1.0.1 使用了Emit构造委托缓存调用,性能客观。提供了类型推导、转换C#代码功能。用于流程图中脚本处理,也可在其他地方进行使用。 MIT README.md diff --git a/Serein.Script/SereinScriptToCsharpScript.cs b/Serein.Script/SereinScriptToCsharpScript.cs index 2a20dbc..615caa0 100644 --- a/Serein.Script/SereinScriptToCsharpScript.cs +++ b/Serein.Script/SereinScriptToCsharpScript.cs @@ -82,12 +82,12 @@ namespace Serein.Script string? returnContent; if (_isTaskMain) { - returnContent = $"global::{taskFullName}"; + returnContent = $"global::{taskFullName}"; sereinScriptMethodInfo.IsAsync = true; } else { - returnContent = $"global::{methodResultType.FullName}"; + returnContent = $"global::{methodResultType.GetFriendlyName()}"; sereinScriptMethodInfo.IsAsync = false; } @@ -118,7 +118,7 @@ namespace Serein.Script { var varName = idf.Name; var varType = _symbolInfos[idf]; - AppendLine($"global::{varType.FullName} {varName} = default; // 变量"); + AppendLine($"global::{varType.GetFriendlyName()} {varName} = default; // 变量"); } AppendLine(""); @@ -163,7 +163,7 @@ namespace Serein.Script ParameterType = type, ParamName = paramName, }); - return $"global::{type.FullName} {paramName}"; + return $"global::{type.GetFriendlyName()} {paramName}"; }); return string.Join(',', values); } @@ -177,7 +177,6 @@ namespace Serein.Script case ReturnNode returnNode: // 程序退出节点 void ConvertCodeOfReturnNode(ReturnNode returnNode) { - Append(Tab); if (returnNode.Value is not null) { @@ -205,7 +204,50 @@ namespace Serein.Script Append("\"\"\""); break; case StringNode stringNode: // 字符串字面量 - Append($"\"{stringNode.Value}\""); + void ConvertCodeOfStringNode(StringNode stringNode) + { + static string EscapeForCSharpString(string input) + { + return input + .Replace("\\", "\\\\") + .Replace("\"", "\\\"") + .Replace("\0", "\\0") + .Replace("\a", "\\a") + .Replace("\b", "\\b") + .Replace("\f", "\\f") + .Replace("\n", "\\n") + .Replace("\r", "\\r") + .Replace("\t", "\\t") + .Replace("\v", "\\v"); + } + var value = stringNode.Value; + var sp = value.Split(Environment.NewLine); + if(sp.Length == 1) + { + Append($"\"{value}\""); + } + else + { + Append($"\""); + foreach (var s in sp) + { + var content = EscapeForCSharpString(s); + if(OperatingSystem.IsWindows()) + { + Append($"\\r\\n{content}"); + } + else if (OperatingSystem.IsLinux()) + { + Append($"\\n{content}"); + } + + } + Append($"\""); + } + + + } + ConvertCodeOfStringNode(stringNode); break; case BooleanNode booleanNode: // 布尔值字面量 Append($"{(booleanNode.Value ? "true" : "false")}"); @@ -333,7 +375,7 @@ namespace Serein.Script { var arrType = this._symbolInfos[arrayDefintionNode]; var tab = new string(' ', (_indentLevel + 1) * 4); - Append($"new global::{arrType.FullName}{{{Environment.NewLine}"); + Append($"new global::{arrType.GetFriendlyName()}{{{Environment.NewLine}"); for (int index = 0; index < arrayDefintionNode.Elements.Count; index++) { ASTNode? e = arrayDefintionNode.Elements[index]; @@ -360,7 +402,7 @@ namespace Serein.Script { var propertyName = property.Key; var propertyType = _symbolInfos[property.Value]; - AppendLine($"public global::{propertyType.FullName} {propertyName} {{ get; set; }}"); + AppendLine($"public global::{propertyType.GetFriendlyName()} {propertyName} {{ get; set; }}"); } Unindent(); AppendLine("}"); @@ -507,7 +549,7 @@ namespace Serein.Script } } - + } diff --git a/Workbench/Serein.WorkBench.csproj b/Workbench/Serein.WorkBench.csproj index 21e22fc..a7ecd34 100644 --- a/Workbench/Serein.WorkBench.csproj +++ b/Workbench/Serein.WorkBench.csproj @@ -49,6 +49,7 @@ +