English 中文(简体)
多界面继承
原标题:does protobuf-net support multiple interface inheritance

I think my question is very similar to this question: Protobuf-net creating typemodel with interface and abstract baseclass however the solution given by Marc here, essentially reduces the multiple inheritance of an abstract class and interface down into a single inheritance design.

对我来说,问题是,我实际上需要 多重接口继承 像这样:

interface ITestBase 
{
}
abstract class TestBase : ITestBase 
{
}
class TestTypeA : TestBase, ITestTypeA 
{
}
interface ITestTypeA 
{
}
class TestTypeB : TestBase, ITestTypeB 
{
}
interface ITestTypeB 
{
}

在这里,我不能轻描淡写,让测试基地实施 ITestTypeA 或 ITestTypeB (这是另一个问题的解决方案), 因为具体等级的测试TypeA 应该同时实施 ITestTypeA 和 ITestbase, 测试TypeB 应该实施 ITestTypeB 和 ITestbase 。

我使用原生泡沫网 v2.0.0.480

问题回答

我找到了这个可行的解决方案。不知道它是否被推荐,或者在运行期间是否会在不知情的情况下破裂,但到目前为止,它似乎对我的测试有效。

因为原生虫-net将接口当作一个具体的序列分类, 它涉及到多个继承问题(我对此的理解是), 所以我所做的只是继承一个基级, 并且没有具体说明任何类与其接口之间的关系。

并创建一个具体的基级, 可以用来定义以下的等级等级。

[ProtoContract]
interface ITestBase 
{
}

[ProtoContract]
[ProtoInclude(1, typeof(TestTypeA))]
[ProtoInclude(2, typeof(TestTypeB))]
abstract class TestBase : ITestBase
{
}

[ProtoContract]
class TestTypeA : TestBase, ITestTypeA 
{
}

[ProtoContract]
interface ITestTypeA 
{
}

[ProtoContract]
class TestTypeB : TestBase, ITestTypeB 
{
}

[ProtoContract]
interface ITestTypeB 
{
}

实际上,在界面前的所有 < code> [Protocontract] 都可能并不重要。 我发现把它们一起拿出来似乎也有效。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签