使用反射动态加载插件

时间:2015-03-25 19:09:19

标签: c# plugins reflection

这是我的代码段

string pluginDirectory = Path.Combine(
    AppDomain.CurrentDomain.BaseDirectory, "Bin");

var pluginAssemblies =
    from file in new DirectoryInfo(pluginDirectory).GetFiles()
    where file.Extension.ToLower() == ".dll"
    select Assembly.LoadFile(file.FullName);

var pluginTypes =
    from assembly in pluginAssemblies
    from type in assembly.GetExportedTypes()
    where typeof(IPaymentProvider).IsAssignableFrom(type)
    where !type.IsAbstract
    where !type.IsGenericTypeDefinition
    select type;

我一直在pluginTypes获得null。我究竟做错了什么?

0 个答案:

没有答案