c# - 在 C# 中聚合接口(interface)

标签 c# .net interface

我有这门课:

class UrlManagementServiceClient : System.ServiceModel.ClientBase<IUrlManagementService>, IUrlManagementService

ClientBase 实现IDisposableICommunicationObject。我也有这个界面:

interface IUrlManagementProxy : IUrlManagementService, ICommunicationObject, IDisposable

但我无法将 UrlManagementServiceClient 对象转换为 IUrlManagementProxy。有什么办法可以做到这一点?我希望最终得到一个可以访问所有三个接口(interface)上的所有方法的对象。

最佳答案

您只能转换为您继承自的接口(interface),要能够转换为IUrlManagementProxy,您需要实现该接口(interface)。

class UrlManagementServiceClient :
   System.ServiceModel.ClientBase<IUrlManagementService>, IUrlManagementProxy

然后您可以将 UrlManagementServiceClient 转换为 UrlManagementProxyIUrlManagementServiceICommunicationObjectIDisposable.

编辑
WCF 生成的类是部分类,这意味着您可以在另一个文件中扩展类定义。放

public partial class UrlManagementServiceClient : IUrlManagementProxy {}

在另一个代码文件中,您的类也将实现完整的 IUrlManagementProxy 接口(interface),然后您可以将其转换为 IUrlManagementProxy

关于c# - 在 C# 中聚合接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6036061/

相关文章:

.net - 为什么百分比的标准数字格式包含空格?

.net - 手机连接电脑

c# - "Test to the Interface"是什么意思?

networking - 在特定网络接口(interface) (JSch) 上打开 SSH 连接

c# - 迭代文件结构时更新进度条

c# - 我可以创建一个只接受 URL 中的大写字母的 ASP MVC 路由吗?

Azure Windows Server 2016 上的 ASP.NET5 CLR 网站正在运行,但在浏览器中出现 404 NOT FOUND

delphi - 这是Delphi 2009中的错误吗?

c# - 如何在 C# 中声明带有可选参数的函数

c# - 如何以编程方式获取解决方案中使用的 NuGet 包的版本?