获取出口从给定的只是一个类型实例的MEF容器 [英] Getting an export from an MEF container given only a Type instance
本文介绍了获取出口从给定的只是一个类型实例的MEF容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一种情况,我必须从我的CompositionContainer中的实例得到一个出口,但我只有一个类型与工作;我不知道在编译时的类型,所以我不能检索正常通用的方式导出的对象。
I have a scenario where I have to get an export from my CompositionContainer instance but I only have a Type to work with; I don't know the type at compile time, hence I can't retrieve the exported object in the normal generic way.
通常你会做到这一点:
_container.GetExportedObject<IMyType>();
但在我的情况,我有这样的:
But in my case, I have this:
Type someType = ... ;
_container.HowDoIGetTheExport(someType);
任何想法?
Any ideas?
推荐答案
找到了答案:
var export = _container.GetExports(someType, null, null).FirstOrDefault();
这篇关于获取出口从给定的只是一个类型实例的MEF容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文