[fix] 修复为了支持嵌套容器导致未检查容器元素类型不能为可空的bug

main
walon 2022-08-09 11:51:21 +08:00
parent 2dd826bafb
commit 154d55f372
5 changed files with 18 additions and 14 deletions

View File

@ -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}' 不存在"); throw new Exception($"table:'{FullName}' 的 value类型:'{ValueType}' 不存在");
} }

View File

@ -273,7 +273,7 @@ namespace Luban.Job.Common.Defs
return Types.Values.Where(v => typeof(T).IsAssignableFrom(v.GetType())).Select(v => (T)v).ToList(); 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); type = DefUtil.TrimBracePairs(type);
int sepIndex = DefUtil.IndexOfBaseTypeEnd(type); int sepIndex = DefUtil.IndexOfBaseTypeEnd(type);
@ -286,11 +286,11 @@ namespace Luban.Job.Common.Defs
} }
else 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; bool nullable;
// 去掉 rawType 两侧的匹配的 () // 去掉 rawType 两侧的匹配的 ()
@ -303,6 +303,10 @@ namespace Luban.Job.Common.Defs
{ {
throw new Exception($"not support nullable type:'{module}.{type}'"); 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; nullable = true;
type = type.Substring(0, type.Length - 1); type = type.Substring(0, type.Length - 1);
} }
@ -363,8 +367,8 @@ namespace Luban.Job.Common.Defs
throw new ArgumentException($"invalid map element type:'{keyValueType}'"); throw new ArgumentException($"invalid map element type:'{keyValueType}'");
} }
return TMap.Create(false, tags, return TMap.Create(false, tags,
CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim()), CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim(), true),
CreateType(module, keyValueType.Substring(typeSepIndex + 1).Trim()), isTreeMap); CreateType(module, keyValueType.Substring(typeSepIndex + 1).Trim(), true), isTreeMap);
} }
protected TType CreateContainerType(string module, string containerType, Dictionary<string, string> containerTags, string elementType) protected TType CreateContainerType(string module, string containerType, Dictionary<string, string> containerTags, string elementType)
@ -373,12 +377,12 @@ namespace Luban.Job.Common.Defs
{ {
case "array": 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": case "set":
{ {
TType type = CreateType(module, elementType); TType type = CreateType(module, elementType, true);
if (type.IsCollection) if (type.IsCollection)
{ {
throw new Exception("set的元素不支持容器类型"); throw new Exception("set的元素不支持容器类型");

View File

@ -117,7 +117,7 @@ namespace Luban.Job.Common.Defs
try try
{ {
CType = AssemblyBase.CreateType(HostType.Namespace, Type); CType = AssemblyBase.CreateType(HostType.Namespace, Type, false);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -40,7 +40,7 @@ namespace Luban.Job.Db.Defs
ass.AddDbTable(this); 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} 类型不合法"); 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类型"); 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} 类型不合法"); throw new Exception($"table:{FullName} value:{ValueType} 类型不合法");
} }

View File

@ -36,12 +36,12 @@ namespace Luban.Job.Proto.Defs
} }
pass.AddProto(this); 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"); 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"); throw new Exception($"rpc name:'{FullName}' res:{ResType} is invalid");
} }