From 38b410f0a5478c99a2ed3a90b9bde9017a338477 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 28 Oct 2021 16:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Denum=E4=B8=8Ebean=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86tags=E5=AF=BC=E8=87=B4=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=94=9F=E6=88=90ref=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++- .../Source/DataCreators/SheetDataCreator.cs | 2 +- src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs | 6 +-- src/Luban.Job.Cfg/Source/Utils/DataUtil.cs | 14 ++----- src/Luban.Job.Cfg/Source/l10n/TextTable.cs | 2 +- .../Source/Defs/DefAssemblyBase.cs | 38 +++++++++++++------ src/Luban.Job.Common/Source/Types/TBean.cs | 6 ++- src/Luban.Job.Common/Source/Types/TEnum.cs | 5 ++- src/Luban.Job.Common/Source/Utils/DefUtil.cs | 33 +++++++++++++++- 9 files changed, 82 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index da082b6..cda50a6 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,16 @@ array与list类型都能表示列表,它们区别在于array生成的代码为 2 -2,4 +2;4 +345 +aaaa|bbbb|cccc +aaabbbccc + + + + +3 +2|4|6 3456 aaaa|bbbb|cccc aaabbbccc diff --git a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs index 79874bb..bbc1b35 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs @@ -481,7 +481,7 @@ namespace Luban.Job.Cfg.DataCreators public DType Accept(TMap type, Sheet sheet, TitleRow row) { - string sep = DataUtil.GetSep(type); + string sep = ""; if (row.Row != null) { diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index a1ed49d..59335ee 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -418,7 +418,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.PreCompile(); defTableRecordType.Compile(); defTableRecordType.PostCompile(); - var tableRecordType = TBean.Create(false, defTableRecordType); + var tableRecordType = TBean.Create(false, defTableRecordType, null); foreach (var file in inputFileInfos) { @@ -485,7 +485,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.PreCompile(); defTableRecordType.Compile(); defTableRecordType.PostCompile(); - var tableRecordType = TBean.Create(false, defTableRecordType); + var tableRecordType = TBean.Create(false, defTableRecordType, null); foreach (var file in inputFileInfos) { @@ -592,7 +592,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.PreCompile(); defTableRecordType.Compile(); defTableRecordType.PostCompile(); - var tableRecordType = TBean.Create(false, defTableRecordType); + var tableRecordType = TBean.Create(false, defTableRecordType, null); foreach (var file in inputFileInfos) { diff --git a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs index e4a57c7..1b4f3f3 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs @@ -139,23 +139,15 @@ namespace Luban.Job.Cfg.Utils return tags.Count > 0 ? tags : null; } - public const string SimpleContainerSep = ",;"; + public const string SimpleContainerSep = ",;|"; - public static string GetSep(TType type) + public static string GetBeanSep(TBean type) { - if (type.Tags != null && type.Tags.TryGetValue("sep", out var s) && !string.IsNullOrWhiteSpace(s)) { return s; } - switch (type) - { - case TBean tb: return (tb.Bean as DefBean).Sep; - case TArray ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : ""; - case TList ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : ""; - case TSet ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : ""; - default: return ""; - } + return ((DefBean)type.Bean).Sep; } public static string GetTypeSep(TType type) diff --git a/src/Luban.Job.Cfg/Source/l10n/TextTable.cs b/src/Luban.Job.Cfg/Source/l10n/TextTable.cs index 089cb96..64e4f83 100644 --- a/src/Luban.Job.Cfg/Source/l10n/TextTable.cs +++ b/src/Luban.Job.Cfg/Source/l10n/TextTable.cs @@ -47,7 +47,7 @@ namespace Luban.Job.Cfg.l10n defTextRowType.PreCompile(); defTextRowType.Compile(); defTextRowType.PostCompile(); - _textRowType = TBean.Create(false, defTextRowType); + _textRowType = TBean.Create(false, defTextRowType, null); } public void AddText(string key, string text) diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index b17835d..b27624e 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -87,37 +87,51 @@ namespace Luban.Job.Common.Defs private readonly Dictionary<(DefTypeBase, bool), TType> _cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>(); - protected TType GetOrCreateTEnum(DefEnum defType, bool nullable) + protected TType GetOrCreateTEnum(DefEnum defType, bool nullable, Dictionary tags) { - if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + if (tags == null || tags.Count == 0) { - return t; + if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + { + return t; + } + else + { + return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType, tags); + } } else { - return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); + return TEnum.Create(nullable, defType, tags); ; } } - protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable) + protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable, Dictionary tags) { - if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + if (tags == null || tags.Count == 0) { - return t; + if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + { + return t; + } + else + { + return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType, tags); + } } else { - return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); + return TBean.Create(nullable, (DefBeanBase)defType, tags); } } - public TType GetDefTType(string module, string type, bool nullable) + public TType GetDefTType(string module, string type, bool nullable, Dictionary tags) { var defType = GetDefType(module, type); switch (defType) { - case DefBeanBase d: return GetOrCreateTBean(d, nullable); - case DefEnum d: return GetOrCreateTEnum(d, nullable); + case DefBeanBase d: return GetOrCreateTBean(d, nullable, tags); + case DefEnum d: return GetOrCreateTEnum(d, nullable, tags); default: return null; } } @@ -202,7 +216,7 @@ namespace Luban.Job.Common.Defs case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型"); default: { - var dtype = GetDefTType(module, type, nullable); + var dtype = GetDefTType(module, type, nullable, tags); if (dtype != null) { return dtype; diff --git a/src/Luban.Job.Common/Source/Types/TBean.cs b/src/Luban.Job.Common/Source/Types/TBean.cs index ff1e1f3..e8e402a 100644 --- a/src/Luban.Job.Common/Source/Types/TBean.cs +++ b/src/Luban.Job.Common/Source/Types/TBean.cs @@ -1,5 +1,6 @@ using Luban.Job.Common.Defs; using Luban.Job.Common.TypeVisitors; +using Luban.Job.Common.Utils; using System; using System.Collections.Generic; @@ -7,9 +8,10 @@ namespace Luban.Job.Common.Types { public class TBean : TType { - public static TBean Create(bool isNullable, DefBeanBase defBean) + public static TBean Create(bool isNullable, DefBeanBase defBean, Dictionary tags) { - return new TBean(isNullable, defBean.Tags, defBean); + // TODO + return new TBean(isNullable, DefUtil.MergeTags(defBean.Tags, tags), defBean); } public DefBeanBase Bean { get; set; } diff --git a/src/Luban.Job.Common/Source/Types/TEnum.cs b/src/Luban.Job.Common/Source/Types/TEnum.cs index 298b49f..cda5570 100644 --- a/src/Luban.Job.Common/Source/Types/TEnum.cs +++ b/src/Luban.Job.Common/Source/Types/TEnum.cs @@ -1,5 +1,6 @@ using Luban.Job.Common.Defs; using Luban.Job.Common.TypeVisitors; +using Luban.Job.Common.Utils; using System; using System.Collections.Generic; @@ -7,9 +8,9 @@ namespace Luban.Job.Common.Types { public class TEnum : TType { - public static TEnum Create(bool isNullable, DefEnum defEnum) + public static TEnum Create(bool isNullable, DefEnum defEnum, Dictionary tags) { - return new TEnum(isNullable, defEnum.Tags, defEnum); + return new TEnum(isNullable, DefUtil.MergeTags(defEnum.Tags, tags), defEnum); } public DefEnum DefineEnum { get; } diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index fd090dd..956df66 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -1,4 +1,5 @@ -using System; +using Bright.Collections; +using System; using System.Collections.Generic; namespace Luban.Job.Common.Utils @@ -123,7 +124,35 @@ namespace Luban.Job.Common.Utils public static bool IsNormalFieldName(string name) { - return !name.StartsWith("__"); + return !name.StartsWith("__") && !name.StartsWith("#"); + } + + public static Dictionary MergeTags(Dictionary tags1, Dictionary tags2) + { + if (tags2 != null && tags2.Count > 0) + { + if (tags1 != null) + { + if (tags1.Count == 0) + { + return tags2; + } + else + { + var result = new Dictionary(tags1); + result.AddAll(tags2); + return result; + } + } + else + { + return tags2; + } + } + else + { + return tags1; + } } } }