Http://msdn.microsoft.com/zh-cn/magazine/ee291628.aspx
Metadata can be used to differentiate export.
You can also use other technologies to differentiate export by adding an attribute to each part.
However, using the original data has its advantages: the instantiation of components can be performed when necessary, which can save resources and improve performance.
[Exportmetadata ("viewtype", "salesorder")] // key-Value Pair [Export (typeof (iview)] public partial class salesorderview: usercontrol, iview {}
// The above Code uses strings directly, which is not good. You can change it
[ExportMetadata(ViewMetadata.ViewType, ViewTypes.SalesOrder)][Export(typeof(IView)]public partial class SalesOrderView : UserControl, IView{ ...}//in a contract assemblypublic enum ViewTypes {SalesOrderView}public class ViewMetadata{ public const string ViewType = "ViewType";}// The following problems still exist
- Metadata keys cannot be found in IDE. The part writer must know the metadata key and type valid for export.
- The compiler does not verify the metadata to ensure it is correct.
- Exportmetadata adds more interference information to the Code to hide the real intent.
Solution:Custom export feature