This project has moved. For the latest updates, please go here.

Question about inheriting MEF attributes

Mar 26, 2010 at 3:08 PM

I've been spending some time looking around for documentation on this behavior, but I am confused on the inheritance on attributes. The documentation on AttributeUsageAttribute.Inherited states: This named parameter specifies whether the indicated attribute can be inherited by derived classes and overriding members.

So in my example, let's say I have the following:

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class InheritedKeywordAttribute : Attribute ...

public class ReusableBase {}

public class DerivedBase : ReusableBase {}


Should this imply that DerivedBase also has the MEF attribute on it, or am I completely misunderstanding what AttributeUsageAttribue.Inherited means?

Any help clearing up this concept would be greatly appreciated, thanks!


Mar 26, 2010 at 5:16 PM

So for attributes in general you are correct however for the purposes of MEF we couldn't follow the standard attribute inheritance rules because of a number of issues not easily worked through. So for MEF's purposes we do a localized view of the attributes (i.e. we pass false for the inherited parameter on GetCustomAttributes). Metadata is never inherited in MEF's eyes and Exports are only inherited if you use the InheritedExportAttribute.

Mar 26, 2010 at 5:22 PM

Thanks a lot for that reply! It's not ideal in the system I'd like to design, but I'm glad I understand that now so I can design around it.