From 7e03fe71929bc701400f15359ea1f3ed6996748f Mon Sep 17 00:00:00 2001 From: walon Date: Sat, 5 Jun 2021 10:32:26 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96cs=20ToString=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=AD=A3=E7=A1=AE=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E7=AA=97=E5=8F=A3=E7=B1=BB=E5=9E=8B=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/Defs/TTypeTemplateCommonExtends.cs | 4 +- .../Source/TypeVisitors/CsToStringVisitor.cs | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/Luban.Job.Common/Source/TypeVisitors/CsToStringVisitor.cs diff --git a/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs b/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs index 8a6c856..2116ae3 100644 --- a/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs +++ b/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs @@ -26,9 +26,9 @@ namespace Luban.Job.Common.Defs return type.Apply(CsDefineTypeName.Ins); } - public static string CsToString(string filedName, TType type) + public static string CsToString(string fieldName, TType type) { - return $"{filedName}"; + return type.Apply(CsToStringVisitor.Ins, fieldName); } public static string CsConstValue(TType type, string value) diff --git a/src/Luban.Job.Common/Source/TypeVisitors/CsToStringVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/CsToStringVisitor.cs new file mode 100644 index 0000000..836fc70 --- /dev/null +++ b/src/Luban.Job.Common/Source/TypeVisitors/CsToStringVisitor.cs @@ -0,0 +1,39 @@ +using Luban.Job.Common.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Luban.Job.Common.TypeVisitors +{ + public class CsToStringVisitor : DecoratorFuncVisitor + { + public static CsToStringVisitor Ins { get; } = new CsToStringVisitor(); + + public override string DoAccept(TType type, string fieldName) + { + return fieldName; + } + + public override string Accept(TArray type, string fieldName) + { + return $"Bright.Common.StringUtil.CollectionToString({fieldName})"; + } + + public override string Accept(TList type, string fieldName) + { + return $"Bright.Common.StringUtil.CollectionToString({fieldName})"; + } + + public override string Accept(TSet type, string fieldName) + { + return $"Bright.Common.StringUtil.CollectionToString({fieldName})"; + } + + public override string Accept(TMap type, string fieldName) + { + return $"Bright.Common.StringUtil.CollectionToString({fieldName})"; + } + } +}