views:

18

answers:

1

Hello,

I often use MEF in my applications but I cannot figure out if there is some way to know if a particular type contains composition members. I could do it easily by retrieving member attributes using reflection but I was wondering if there was already a helper class or something like this which could do this work for me.

At least the MEF programming guide does not metion anything about that.

Thanks.


Edit:
My actual scenario is that in a MVVM WPF application and I created a base Window class which automatically compose on construction, but as not all implementation are using MEF at their current state I would like to avoid composition if these implementations does not define any composable members. Maybe composing a class with no composable members does not imply a big CPU time. In fact I just want to be clean.

A: 

Why do you need to know if a type is composable with MEF?

In any case, one thing you could do is call AttributedModelServices.CreatePartDefinition and check to see whether the ImportDefinitions and ExportDefinitions property of the returned part definition are empty. If they both are empty then the type doesn't use MEF.

Daniel Plaisted
In fact, I am actually using composition in a MVVM WPF application and I created a base Window class which automatically compose on construction, but as not all implementation are using MEF at their current state I would like to avoid composition if these implementations does not define any composable members. Maybe composing a class with no composable members does not imply a big CPU time. In fact I just want to be clean.
Ucodia
@Ucodia I don't think composing a class with no composable members is going to ever be measurably more expensive than checking to see whether it has any composable members, so I would recommend that in your case you just always compose it.
Daniel Plaisted
I will just make some performance tests and publish them here to have an idea of how much it could costs.
Ucodia