C# protobuf.net继承-使用ImplicitFields=ImplicitFields.AllFields
我有一个基类,它用[ProtoContract(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
为了能够序列化派生类,我是否只需要添加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
{ ... }