Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MEF be used to get the System.Type of classes marked [Export]?

Tags:

.net

mef

I've been successfully using MEF to obtain exported class instances. However, I came across a situation where I need to enumerate a set of exported derived classes without instantiating them. I've looked up CompositionContainer's documentation and it only seems to be able to return object instances.

I know I could have a static Type field in each derived class and export it, or do my own reflection, but I'd like to know if there's a build-in way to mark classes with the [Export] attribute and then enumerate their System.Type.

like image 449
Trillian Avatar asked Aug 11 '10 16:08

Trillian


1 Answers

As leppie said, there's no built in way to do this. This is by design. There's not necessarily a one-to-one mapping between exports and types (any number of parts could have property exports of type String, for example). Also, with different programming models, the part may have come from a configuration file or a dynamic programming language, so trying to get the CLR type associated with it might not make much sense.

like image 90
Daniel Plaisted Avatar answered Nov 11 '22 21:11

Daniel Plaisted