feat:支持多维数组嵌套
parent
d6ad1e64c4
commit
6620cca6e1
|
|
@ -92,7 +92,20 @@ namespace Luban.Job.Cfg.TypeVisitors
|
|||
string __v = $"__v{Flag}";
|
||||
string __json = $"__json{Flag}";
|
||||
string __index = $"__index{Flag}";
|
||||
return $"{{ var {__json} = {json}; int {_n} = {__json}.GetArrayLength(); {x} = new {type.ElementType.CsUnderingDefineType()}[{_n}]; int {__index}=0; foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}")} {x}[{__index}++] = {__v}; }} }}";
|
||||
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{_n}]";
|
||||
if (type.Dimension > 1)
|
||||
{
|
||||
if (type.FinalElementType == null)
|
||||
{
|
||||
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
|
||||
}
|
||||
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{_n}]";
|
||||
for (int i = 0; i < type.Dimension - 1; i++)
|
||||
{
|
||||
typeStr += "[]";
|
||||
}
|
||||
}
|
||||
return $"{{ var {__json} = {json}; int {_n} = {__json}.GetArrayLength(); {x} = new {typeStr}; int {__index}=0; foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}")} {x}[{__index}++] = {__v}; }} }}";
|
||||
}
|
||||
|
||||
public string Accept(TList type, string json, string x)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,20 @@ namespace Luban.Job.Cfg.TypeVisitors
|
|||
string __json = $"__json{Flag}";
|
||||
string __index = $"__index{Flag}";
|
||||
string tempJsonName = __json;
|
||||
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} int {_n} = {tempJsonName}.Count; {x} = new {type.ElementType.CsUnderingDefineType()}[{_n}]; int {__index}=0; foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, __e, __v)} {x}[{__index}++] = {__v}; }} }}";
|
||||
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{_n}]";
|
||||
if (type.Dimension > 1)
|
||||
{
|
||||
if (type.FinalElementType == null)
|
||||
{
|
||||
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
|
||||
}
|
||||
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{_n}]";
|
||||
for (int i = 0; i < type.Dimension - 1; i++)
|
||||
{
|
||||
typeStr += "[]";
|
||||
}
|
||||
}
|
||||
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} int {_n} = {tempJsonName}.Count; {x} = new {typeStr}; int {__index}=0; foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, __e, __v)} {x}[{__index}++] = {__v}; }} }}";
|
||||
}
|
||||
|
||||
public string Accept(TList type, string json, string x)
|
||||
|
|
|
|||
|
|
@ -373,12 +373,7 @@ namespace Luban.Job.Common.Defs
|
|||
{
|
||||
case "array":
|
||||
{
|
||||
TType type = CreateType(module, elementType);
|
||||
if (type.TypeName == "array")
|
||||
{
|
||||
throw new Exception("不支持多维数组,请改为嵌套list");
|
||||
}
|
||||
return TArray.Create(false, containerTags, type);
|
||||
return TArray.Create(false, containerTags, CreateType(module, elementType));
|
||||
}
|
||||
case "list": return TList.Create(false, containerTags, CreateType(module, elementType), true);
|
||||
case "set":
|
||||
|
|
|
|||
|
|
@ -88,10 +88,23 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
public string Accept(TArray type, string bufName, string fieldName)
|
||||
{
|
||||
Flag++;
|
||||
string n = $"n{Flag}";
|
||||
string _e = $"_e{Flag}";
|
||||
string i = $"i{Flag}";
|
||||
return $"{{int {n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.ElementType.Apply(CsDefineTypeName.Ins)}[{n}];for(var {i} = 0 ; {i} < {n} ; {i}++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} {_e};{type.ElementType.Apply(this, bufName, $"{_e}")} {fieldName}[{i}] = {_e};}}}}";
|
||||
string __n = $"__n{Flag}";
|
||||
string __e = $"__e{Flag}";
|
||||
string __index = $"__index{Flag}";
|
||||
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{__n}]";
|
||||
if (type.Dimension > 1)
|
||||
{
|
||||
if (type.FinalElementType == null)
|
||||
{
|
||||
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
|
||||
}
|
||||
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{__n}]";
|
||||
for (int i = 0; i < type.Dimension - 1; i++)
|
||||
{
|
||||
typeStr += "[]";
|
||||
}
|
||||
}
|
||||
return $"{{int {__n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {typeStr};for(var {__index} = 0 ; {__index} < {__n} ; {__index}++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} {__e};{type.ElementType.Apply(this, bufName, $"{__e}")} {fieldName}[{__index}] = {__e};}}}}";
|
||||
}
|
||||
|
||||
public string Accept(TList type, string bufName, string fieldName)
|
||||
|
|
|
|||
|
|
@ -15,10 +15,21 @@ namespace Luban.Job.Common.Types
|
|||
public override TType ElementType { get; }
|
||||
|
||||
public override string TypeName => "array";
|
||||
public int Dimension { get; } = 1;
|
||||
public TType FinalElementType { get; }
|
||||
|
||||
private TArray(bool isNullable, Dictionary<string, string> tags, TType elementType) : base(isNullable, tags)
|
||||
{
|
||||
ElementType = elementType;
|
||||
if (!elementType.IsCollection)
|
||||
{
|
||||
FinalElementType = ElementType;
|
||||
}
|
||||
if (ElementType.TypeName == "array")
|
||||
{
|
||||
Dimension = (ElementType as TArray).Dimension + 1;
|
||||
FinalElementType = (ElementType as TArray).FinalElementType;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryParseFrom(string s)
|
||||
|
|
|
|||
Loading…
Reference in New Issue