[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}' 不存在");
}

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();
}
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<string, string> 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的元素不支持容器类型");

View File

@ -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)
{

View File

@ -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} 类型不合法");
}

View File

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