MEF: articles in the msdn magazine (10) differentiate export using metadata

Source: Internet
Author: User

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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.