【发布时间】:2011-01-14 10:40:08
【问题描述】:
我在转换/类型等方面遇到问题。
首先,我的查询是此处另一篇文章的后续内容: Initialize generic object from a System.Type
那么继续这个问题,我该如何使用我新创建的对象的方法?
即我想做的如下:
Type iFace = typeof(IService1);
Type genericListType = typeof(System.ServiceModel.ChannelFactory<>).MakeGenericType(iFace);
object factory = Activator.CreateInstance(genericListType, new object[]
{
new BasicHttpBinding(),
new EndpointAddress("http://localhost:1693/Service.svc")
});
var channel = factory.CreateChannel();
顺便说一句,虽然我正在将此应用程序用于 WCF,但这不是 WCF 问题
【问题讨论】:
标签: c# reflection types casting generics