我目前正在与 MEF 合作并面临一些问题
我想要的是从目录中加载 dll。
首先我扫描目录并将两件事保存在字典中
来自相应 DLL 的名称属性(作为字符串)
和模块名称(作为字符串)
这是 ScanDirectory() 代码
private void ScanPluginDirectory()
{
catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\plugin"));
container = new CompositionContainer(catalog);
batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch);
pluginDictionary = new Dictionary<String, String>();
foreach (IFilter filter in filters)
{
Type t = filter.GetType();
pluginDictionary.Add(filter.Name, t.Module.Name);
}
}
并在复选框列表中显示他们的名字。从复选框中选择 dll。
我有进口声明
[Import]
public IEnumerable<IFilter> filters { get; set; }
目前我的程序运行良好。我所做的是当我从复选框列表中检查插件时。它将其移动到“已加载”目录中,并且 QueryPlugin() 方法会查看“已加载”目录以搜索插件。
从复选框列表中取消选中插件后。我将它移出“加载”目录...
我想要的是使用 batch.RemovePart() 方法来摆脱 dll 从一个目录到另一个目录的快速移动......
注意:我不会使用手动将插件添加到批处理中
batch.AddPart(new DemoFilter1());
而不是这个我使用 DirectoryCatalog();;