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})"; + } + } +}