c#如何调用php接口方法参数类型,c# – .NET:使用通用接口参数调用Assembly obj的GetInterface方法...

我有以下界面:

public interface PluginInterface where T : MyData

{

List GetTableData();

}

在一个单独的程序集中,我有一个实现此接口的类.实际上,实现此接口的所有类都在单独的程序集中.原因是将我的应用程序设计为插件主机,其中插件可以在将来完成,只要它们实现上述接口并将程序集DLL复制到相应的文件夹即可.

我的应用程序通过首先加载程序集来发现插件并执行以下操作:

List> Plugins = new List>();

string FileName = ...;//name of the DLL file that contains classes that implement the interface

Assembly Asm = Assembly.LoadFile(Filename);

foreach (Type AsmType in Asm.GetTypes())

{

//Type type = AsmType.GetInterface("PluginInterface", true); //

Type type = AsmType.GetInterface("PluginInterface", true);

if (type != null)

{

PluginInterface Plugin = (PluginInterface)Activator.CreateInstance(AsmType);

Plugins.Add(Plugin);

}

}

问题是因为我通过Type type = …来获取类型的行似乎都不起作用,因为两者似乎都是null.我觉得通用以某种方式造成了麻烦.你知道为什么吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值