From 06467344a57a90dde4060f8bc059e9daf5b8ecdb Mon Sep 17 00:00:00 2001 From: walon Date: Sun, 24 Oct 2021 20:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=89=B9=E6=80=A7=E3=80=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=BA=E5=AE=B9=E5=99=A8=E7=B1=BB=E5=9E=8B=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E5=8F=8Akey,value=E7=B1=BB=E5=9E=8B=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=B1=9E=E6=80=A7=EF=BC=88=E4=BE=8B=E5=A6=82?= =?UTF-8?q?=20map,(int&ref=3Dtest),(int&path=3Dunity)&tag=5Fof=5Fmap=3Dxxx?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataCreators/ExcelStreamDataCreator.cs | 19 --------------- .../DataCreators/InvalidExcelDataException.cs | 24 +++++++++++++++++++ .../Source/Defs/DefAssemblyBase.cs | 22 +++++++++++++---- src/Luban.Job.Common/Source/Utils/DefUtil.cs | 24 +++++++++++++++---- 4 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 src/Luban.Job.Cfg/Source/DataCreators/InvalidExcelDataException.cs diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelStreamDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelStreamDataCreator.cs index 988e246..8b08a4a 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelStreamDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelStreamDataCreator.cs @@ -8,28 +8,9 @@ using Luban.Job.Common.Types; using Luban.Job.Common.TypeVisitors; using System; using System.Collections.Generic; -using System.Runtime.Serialization; namespace Luban.Job.Cfg.DataCreators { - class InvalidExcelDataException : Exception - { - public InvalidExcelDataException() - { - } - - public InvalidExcelDataException(string message) : base(message) - { - } - - public InvalidExcelDataException(string message, Exception innerException) : base(message, innerException) - { - } - - protected InvalidExcelDataException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } class ExcelStreamDataCreator : ITypeFuncVisitor { diff --git a/src/Luban.Job.Cfg/Source/DataCreators/InvalidExcelDataException.cs b/src/Luban.Job.Cfg/Source/DataCreators/InvalidExcelDataException.cs new file mode 100644 index 0000000..e8fe2b9 --- /dev/null +++ b/src/Luban.Job.Cfg/Source/DataCreators/InvalidExcelDataException.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.Serialization; + +namespace Luban.Job.Cfg.DataCreators +{ + class InvalidExcelDataException : Exception + { + public InvalidExcelDataException() + { + } + + public InvalidExcelDataException(string message) : base(message) + { + } + + public InvalidExcelDataException(string message, Exception innerException) : base(message, innerException) + { + } + + protected InvalidExcelDataException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 75adab0..ec4880e 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -73,29 +73,29 @@ namespace Luban.Job.Common.Defs } } - private readonly Dictionary<(DefTypeBase, bool), TType> cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>(); + private readonly Dictionary<(DefTypeBase, bool), TType> _cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>(); protected TType GetOrCreateTEnum(DefEnum defType, bool nullable) { - if (cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) { return t; } else { - return cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); + return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); } } protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable) { - if (cacheDefTTypes.TryGetValue((defType, nullable), out var t)) + if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) { return t; } else { - return cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); + return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); } } @@ -137,6 +137,18 @@ namespace Luban.Job.Common.Defs protected TType CreateNotContainerType(string module, string rawType) { bool nullable; + // 去掉 rawType 两侧的匹配的 () + while (rawType.Length > 0 && rawType[0] == '(') + { + if (rawType[rawType.Length - 1] == ')') + { + rawType = rawType.Substring(1, rawType.Length - 2); + } + else + { + throw new Exception($"type:{rawType} brace not match"); + } + } var (type, tags) = DefUtil.ParseType(rawType); #if !LUBAN_LITE diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index b5ed8e0..eeeab80 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -44,11 +44,25 @@ namespace Luban.Job.Common.Utils } else { -#if !LUBAN_LITE - return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..])); -#else - return (s.Substring(0, sepIndex), ParseAttrs(s.Substring(sepIndex + 1))); -#endif + int braceDepth = 0; + for (int i = 0; i < s.Length; i++) + { + var c = s[i]; + if (c == '(') + { + ++braceDepth; + } + else if (c == ')') + { + --braceDepth; + } + + if (braceDepth == 0 && (c == '#' || c == '&' || c == '|')) + { + return (s.Substring(0, i), ParseAttrs(s.Substring(i + 1))); + } + } + return (s, new Dictionary()); } }