diff --git a/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs index dae970f..0fcada8 100644 --- a/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs +++ b/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs @@ -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); - } } } diff --git a/src/Luban.Server/Templates/proto/cs/bean.tpl b/src/Luban.Server/Templates/proto/cs/bean.tpl index 1e3006a..20275fc 100644 --- a/src/Luban.Server/Templates/proto/cs/bean.tpl +++ b/src/Luban.Server/Templates/proto/cs/bean.tpl @@ -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); - } + _buf.WriteInt(x.GetTypeId()); + x.Serialize(_buf); {{~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~}}