我可以编写一个类来使用 mef 导入实现特定接口(interface)的所有类型,然后在运行时指定该接口(interface)吗? (我知道我需要用导出来标记实现者)
示例用法:
IEnumerable<IExcitingClass> excitingClasses = ClassImporter<IExcitingInterface>.ImportAllFrom(specifyDirectory);
这可能吗?
最佳答案
您可以使用 DirectoryCatalog 创建一个容器,然后调用 container.GetExportedValues<IExcitingClass>
.这是你想要的吗?
关于c# - Mef 导入实现在运行时指定的接口(interface)的所有类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5109047/