如何序列化一个类实现两个具有相同基础接口的接口
我正在尝试使用protobuf v2序列化类A实现接口B和C。并且B和C都从D派生。
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(B))
[ProtoBuf.Includes(101, typeof(C))
interface D{...}
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(A))
interface B:interfae D{...}
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(A))
interface C:interface D
{
...
}
[ProtoBuf.ProtoContract]
class A: interface B, interface C{...}
将返回错误:一种类型只能参与一个继承层次结构。
I am trying use protobuf v2 to serialize a class A implements interfaces B and C. And both B and C derived from D.
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(B))
[ProtoBuf.Includes(101, typeof(C))
interface D{...}
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(A))
interface B:interfae D{...}
[ProtoBuf.ProtoContract]
[ProtoBuf.Includes(101, typeof(A))
interface C:interface D
{
...
}
[ProtoBuf.ProtoContract]
class A: interface B, interface C{...}
There will return error: a type can only participate in one inheritance hierarchy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
接口实际上与类继承不是同一类型的“派生”(继承)。虽然提供了基本接口支持,但这不是 protobuf-net 目前支持的场景。
至于它是否可以支持它——这需要一些思考。我建议在此处记录请求< /a>.
Interfaces are not really the same kind of "derived" (inheritance) as class inheritance. While basic interface support is provided, this is not a scenario that protobuf-net currently supports.
As to whether it could support it - that would take some thought. I would suggest logging a request, here.