From 154d55f37284748a8128bff399716c4858b6f394 Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 9 Aug 2022 11:51:21 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E4=B8=BA=E4=BA=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B5=8C=E5=A5=97=E5=AE=B9=E5=99=A8=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=9C=AA=E6=A3=80=E6=9F=A5=E5=AE=B9=E5=99=A8=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=B1=BB=E5=9E=8B=E4=B8=8D=E8=83=BD=E4=B8=BA=E5=8F=AF?= =?UTF-8?q?=E7=A9=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/Defs/DefTable.cs | 2 +- .../Source/Defs/DefAssemblyBase.cs | 20 +++++++++++-------- .../Source/Defs/DefFieldBase.cs | 2 +- src/Luban.Job.Db/Source/Defs/DefTable.cs | 4 ++-- src/Luban.Job.Proto/Source/Defs/DefRpc.cs | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs index fe83962..eb3ca88 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs @@ -92,7 +92,7 @@ namespace Luban.Job.Cfg.Defs } } - if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null) + if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType, false)) == null) { throw new Exception($"table:'{FullName}' 的 value类型:'{ValueType}' 不存在"); } diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 8c72367..eaaef2d 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -273,7 +273,7 @@ namespace Luban.Job.Common.Defs return Types.Values.Where(v => typeof(T).IsAssignableFrom(v.GetType())).Select(v => (T)v).ToList(); } - public TType CreateType(string module, string type) + public TType CreateType(string module, string type, bool containerElementType) { type = DefUtil.TrimBracePairs(type); int sepIndex = DefUtil.IndexOfBaseTypeEnd(type); @@ -286,11 +286,11 @@ namespace Luban.Job.Common.Defs } else { - return CreateNotContainerType(module, type); + return CreateNotContainerType(module, type, containerElementType); } } - protected TType CreateNotContainerType(string module, string rawType) + protected TType CreateNotContainerType(string module, string rawType, bool containerElementType) { bool nullable; // 去掉 rawType 两侧的匹配的 () @@ -303,6 +303,10 @@ namespace Luban.Job.Common.Defs { throw new Exception($"not support nullable type:'{module}.{type}'"); } + if (containerElementType) + { + throw new Exception($"container element type can't be nullable type:'{module}.{type}'"); + } nullable = true; type = type.Substring(0, type.Length - 1); } @@ -363,8 +367,8 @@ namespace Luban.Job.Common.Defs throw new ArgumentException($"invalid map element type:'{keyValueType}'"); } return TMap.Create(false, tags, - CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim()), - CreateType(module, keyValueType.Substring(typeSepIndex + 1).Trim()), isTreeMap); + CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim(), true), + CreateType(module, keyValueType.Substring(typeSepIndex + 1).Trim(), true), isTreeMap); } protected TType CreateContainerType(string module, string containerType, Dictionary containerTags, string elementType) @@ -373,12 +377,12 @@ namespace Luban.Job.Common.Defs { case "array": { - return TArray.Create(false, containerTags, CreateType(module, elementType)); + return TArray.Create(false, containerTags, CreateType(module, elementType, true)); } - case "list": return TList.Create(false, containerTags, CreateType(module, elementType), true); + case "list": return TList.Create(false, containerTags, CreateType(module, elementType, true), true); case "set": { - TType type = CreateType(module, elementType); + TType type = CreateType(module, elementType, true); if (type.IsCollection) { throw new Exception("set的元素不支持容器类型"); diff --git a/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs b/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs index 7502a4c..394098c 100644 --- a/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs @@ -117,7 +117,7 @@ namespace Luban.Job.Common.Defs try { - CType = AssemblyBase.CreateType(HostType.Namespace, Type); + CType = AssemblyBase.CreateType(HostType.Namespace, Type, false); } catch (Exception e) { diff --git a/src/Luban.Job.Db/Source/Defs/DefTable.cs b/src/Luban.Job.Db/Source/Defs/DefTable.cs index 409b002..03758d6 100644 --- a/src/Luban.Job.Db/Source/Defs/DefTable.cs +++ b/src/Luban.Job.Db/Source/Defs/DefTable.cs @@ -40,7 +40,7 @@ namespace Luban.Job.Db.Defs ass.AddDbTable(this); - if ((KeyTType = ass.CreateType(Namespace, KeyType)) == null) + if ((KeyTType = ass.CreateType(Namespace, KeyType, false)) == null) { throw new Exception($"table:{FullName} key:{KeyType} 类型不合法"); } @@ -50,7 +50,7 @@ namespace Luban.Job.Db.Defs throw new Exception($"table:{FullName} key:{KeyTType} 不支持。只支持long与string类型"); } - if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null) + if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType, false)) == null) { throw new Exception($"table:{FullName} value:{ValueType} 类型不合法"); } diff --git a/src/Luban.Job.Proto/Source/Defs/DefRpc.cs b/src/Luban.Job.Proto/Source/Defs/DefRpc.cs index 53e2e2a..284940b 100644 --- a/src/Luban.Job.Proto/Source/Defs/DefRpc.cs +++ b/src/Luban.Job.Proto/Source/Defs/DefRpc.cs @@ -36,12 +36,12 @@ namespace Luban.Job.Proto.Defs } pass.AddProto(this); - if ((TArgType = Assembly.CreateType(Namespace, ArgType)) == null) + if ((TArgType = Assembly.CreateType(Namespace, ArgType, false)) == null) { throw new Exception($"rpc name:'{FullName}' arg:{ArgType} is invalid"); } - if ((TResType = Assembly.CreateType(Namespace, ResType)) == null) + if ((TResType = Assembly.CreateType(Namespace, ResType, false)) == null) { throw new Exception($"rpc name:'{FullName}' res:{ResType} is invalid"); }