如何序列化一个类实现了两个具有相同基础接口的接口 [英] how to serialize a class implements two interfaces who have same based interface

查看:62
本文介绍了如何序列化一个类实现了两个具有相同基础接口的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用protobuf v2序列化一个类A,以实现接口B和C.并且B和C都从D派生.

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.

推荐答案

接口与 class 继承实际上不是同一类派生"(继承).虽然提供了 basic 接口支持,但这不是protobuf-net当前支持的方案.

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.

这篇关于如何序列化一个类实现了两个具有相同基础接口的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆