PartMetadata vs. ExportMetadata

Mar 26, 2010 at 4:03 AM
Edited Mar 26, 2010 at 4:31 AM

In the "MEF Programming Guide," ExportMetadata and PartMetadata are both briefly discussed in different contexts. How do these two relate? Does any part of MEF consume the PartMetadata?

Thanks!
Ryan 

Developer
Mar 26, 2010 at 6:12 PM

Nothing in MEF today actually consumes PartMetadata, its primary purpose was to allow for people to write FilteredCatalogs (http://mef.codeplex.com/wikipage?title=Filtering%20Catalogs&referringTitle=Guide). ExportMetadata is potentially consumed by importers.

Jan 8, 2013 at 4:42 PM

Just in case someone stumbles upon this thread, the above answer is outdated. PartMetadata is used in the implementation of open-generics (and possibly other places I am not aware of).

When using open generics to export a part, two keys are added to the part's metadata dictionary:

  1. "System.ComponentModel.Composition.IsGenericPart" - set to "true" for open generics
  2. "System.ComponentModel.Composition.GenericPartArity" - set to the number of type parameters in the generic part.

These entries are handled internally by MEF, so there's no special need to know this unless you're trying to do some low-level stuff.