参加 2 个课程 - 本质上
我有一个对第 3 方 WSDL 的 .NET Web 服务参考。
该参考文献中有 2 个类。基本上,这 2 个类很可能是第 3 方 API 端的接口,但在 .NET 中最终成为 2 个代理类。
我需要将这两个类合并为一个类。为什么?因为将它们分开是愚蠢的,所以它们是允许我进行方法调用的服务。方法调用都在这两个代理类之间各占一半。
因此,我想创建一个名为 ThirdPartyService 的自定义包装类,并以某种方式本质上继承这些代理类的成员。我知道你可以在 C# 中继承 2 个类,但我也不知道如何使用接口来做到这一点。
I've got a .NET Web Service Reference to a 3rd party WSDL.
In that reference are 2 classes. Basically these 2 classes are most likely Interfaces on the 3rd Party API side but in .NET end up as 2 proxy classes.
I have a need to combine both these classes into one class. Why? Because it's stupid that these are split, they're the service which allows me to make method calls. The method calls are all split half and half between these 2 proxy classes.
So I want to create a custom wrapper class called ThirdPartyService and somehow essentially inherit both those proxy class's members. I know you can inherit 2 classes in C# but I don't see how to do this with an interface either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,你没有给我们太多的帮助,但你可以使用组合来做到这一点。
那么
如果
Foo
和Bar
分别实现接口IFoo
和IBar
那么你就可以拥有FooAndBar
也实现IFoo
和IBar
。用设计模式的语言来说,我们将其称为适配器模式。
关于您的编辑:
不可以。您不能从 C# 中的两个类继承。你必须像我已经解释过的那样使用组合。
Well, you haven't given us a lot to work with, but you could do this using composition.
Then
If
Foo
andBar
implement interfacesIFoo
andIBar
respectively then you can haveFooAndBar
implementIFoo
andIBar
too.In the language of Design Patterns we would call this the adapter pattern.
Regarding your edit:
No. You can not inherit from two classes in C#. You have to use composition like I already explained.
也许为了给 Jason 的帖子添加一些价值,这类内容也被称为 适配器
Maybe to add some value to Jason's post, this sort of stuff would also be known as adapter