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()); } }