Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# protobuf.net继承-使用ImplicitFields=ImplicitFields.AllFields_C#_Protobuf Net - Fatal编程技术网

C# protobuf.net继承-使用ImplicitFields=ImplicitFields.AllFields

C# protobuf.net继承-使用ImplicitFields=ImplicitFields.AllFields,c#,protobuf-net,C#,Protobuf Net,我有一个基类,它用[ProtoContract(ImplicitFields=ImplicitFields.AllFields)]修饰 为了能够序列化派生类,我是否只需要添加ProtoInclude?由于派生类字段未被序列化-继承是否仅适用于Protomember?Protobuf不完全支持继承,您需要在基类中进行一些修饰 [ ProtoContract(), ProtoInclude(100, typeof(Peer)), ProtoInclude(101, typeof(Instructio

我有一个基类,它用[ProtoContract(ImplicitFields=ImplicitFields.AllFields)]修饰


为了能够序列化派生类,我是否只需要添加ProtoInclude?由于派生类字段未被序列化-继承是否仅适用于Protomember?

Protobuf不完全支持继承,您需要在基类中进行一些修饰

[
ProtoContract(),
ProtoInclude(100, typeof(Peer)),
ProtoInclude(101, typeof(Instruction))
]
class Base {...}

[ProtoContract()]
class Peer: Base
{ ... }

[ProtoContract()]
class Instruction: Base
{ ... }

对于仅通过基类提供属性的派生类。

您应该查看之前提出的问题,接受答案或改进您的问题,以便让参与交易的人满意,您对答案进行评分和/或接受答案。只需添加:
ImplicitFields
不被认为是继承的:这需要在每个级别应用。
[
ProtoContract(),
ProtoInclude(100, typeof(Peer)),
ProtoInclude(101, typeof(Instruction))
]
class Base {...}

[ProtoContract()]
class Peer: Base
{ ... }

[ProtoContract()]
class Instruction: Base
{ ... }