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