tags:

views:

87

answers:

1

Hi all

apologies for the title, I got stuck for words

I'm dipping my toes in the MEF pond. So far, so good. I've got a host app and a couple of "plugin" assemblies that export things. The host app defines an attribute called DescriptionAttribute which inherits from ExportAttribute and has a simple Name property. My test form has an <ImportMany> IEnumerable(Of Lazy(Of IDoStuff, IDescriptionAttribute)). This gets nicely filled by MEF, I can spin through the collection, the Name property is filled in, life is golden. I'll split things out into separate assemblies later on, at the moment it's just a proof of concept.

Now, the question is: Is there any way I can expose the assembly version of the IDoStuff implementing, DescriptionAttribute wearing "plugin" classes through the DescriptionAttribute attribute that I have? All my attempts so far at passing it to the constructor of the attribute have failed, studio keeps telling me that a constant expression is required (understandably). I can expose it through the IDoStuff interface, but it'd be much nicer to have it as part of the DescriptionAttribute attribute instead, that "feels" better. I can also hardcode it, but it's another spot that I'd forget to update when releasing a new version of a "plugin" :-)

+1  A: 

So you have a bunch of instances of classes that implement IDoStuff, imported by MEF, and you want to know the assembly version for each of them?

Can you do this? GetType() will return the type of the underlying class, right? Not typeof(IDoStuff)?

// IDoStuff myStuffDoer
var version = myStuffDoer.GetType().Assembly.GetName().Version;
Matt Hamilton
Ah, the 'ol GetType, I keep forgetting about that one. Yep, that'd be a workable solution. And if I need something other than that, I could hardcoded it as a parameter to the DescriptionAttribute attribute.I tried it, it works, you're a champion Matt!
Dan F