我有以下界面:
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.我觉得通用以某种方式造成了麻烦.你知道为什么吗?