我有这门课:
class UrlManagementServiceClient : System.ServiceModel.ClientBase<IUrlManagementService>, IUrlManagementService
ClientBase 实现IDisposable
和ICommunicationObject
。我也有这个界面:
interface IUrlManagementProxy : IUrlManagementService, ICommunicationObject, IDisposable
但我无法将 UrlManagementServiceClient
对象转换为 IUrlManagementProxy
。有什么办法可以做到这一点?我希望最终得到一个可以访问所有三个接口(interface)上的所有方法的对象。
最佳答案
您只能转换为您继承自的接口(interface),要能够转换为IUrlManagementProxy
,您需要实现该接口(interface)。
class UrlManagementServiceClient :
System.ServiceModel.ClientBase<IUrlManagementService>, IUrlManagementProxy
然后您可以将 UrlManagementServiceClient
转换为 UrlManagementProxy
、IUrlManagementService
、ICommunicationObject
或 IDisposable
.
编辑
WCF 生成的类是部分类,这意味着您可以在另一个文件中扩展类定义。放
public partial class UrlManagementServiceClient : IUrlManagementProxy {}
在另一个代码文件中,您的类也将实现完整的 IUrlManagementProxy
接口(interface),然后您可以将其转换为 IUrlManagementProxy
。
关于c# - 在 C# 中聚合接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6036061/