Alex Rivera | Logout

Getting an export from an MEF container given only a Type instance

Asked 2009-06-24T11:33:26.203
12

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.

Normally you would do this:

_container.GetExportedObject<IMyType>();

But in my case, I have this:

Type someType = ... ;
_container.HowDoIGetTheExport(someType);

Any ideas?

Edit
Report

1 Answer

22

Found the answer:

var export = _container.GetExports(someType, null, null).FirstOrDefault();
answered 2009-06-24T12:02:31.670

Your Answer