【修复】修复proto c#对可空变量序列化的bug
parent
c52407bdee
commit
034f0dd21b
|
|
@ -10,17 +10,12 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
{
|
||||
if (type.IsNullable)
|
||||
{
|
||||
return $"if({fieldName} != null){{ {bufName}.WriteBool(true); {type.Apply(CsUnderingSerializeVisitor.Ins, bufName, type.Apply(CsIsRawNullableTypeVisitor.Ins) ? fieldName : fieldName + ".Value" )} }} else {{ {bufName}.WriteBool(true); }}";
|
||||
return $"{{ if({fieldName} is {type.Apply(CsUnderingDefineTypeName.Ins)} __value__){{ {bufName}.WriteBool(true); {type.Apply(CsUnderingSerializeVisitor.Ins, bufName, "__value__" )} }} else {{ {bufName}.WriteBool(false); }} }}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Accept(TBean type, string bufName, string fieldName)
|
||||
{
|
||||
return type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,15 +40,8 @@ namespace {{x.namespace_with_top_module}}
|
|||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
if (x != null)
|
||||
{
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
_buf.WriteInt(0);
|
||||
}
|
||||
{{~else~}}
|
||||
x.Serialize(_buf);
|
||||
{{~end~}}
|
||||
|
|
@ -60,7 +53,6 @@ namespace {{x.namespace_with_top_module}}
|
|||
{{full_name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue