MEF框架ExportMetadata使用示例
Namespace System.ComponentModel.Composition
Public NotInheritable Class ExportMetadataAttribute
Inherits Attribute
使用示例:
[ExportMetadata(“Name“,“李四“)]
[Export(typeof(Users))]
public class Users
{
public string UserName = “张三“;
}
[Export(typeof(Users))]
public class Users
{
public string UserName = “张三“;
}
public interface IMetadata
{
string Name { get; }
}
{
string Name { get; }
}
定义Import时
[Import(typeof(Users))]
public Lazy<Users,IMetadata> Users { get; set; }
public Lazy<Users,IMetadata> Users { get; set; }
使用时:
MessageBox.Show(Users.Value.UserName);
Users.MetaData.Name
ExportMetadata会自动映射到IMetaData接口中