首页 > 学院 > 开发设计 > 正文

MEF example code

2019-11-17 02:25:02
字体:
来源:转载
供稿:网友
MEF example code

public interface IObjectResolver    {    }public class ObjectResolver:IObjectResolver    {      PRivate CompositionContainer container;      public ObjectResolver()      {          container = new CompositionContainer(new AggregateCatalog());      }      public void AddCatalogFile(string fileName)      {          if (!File.Exists(fileName))              throw new FileNotFoundException();          AggregateCatalog catalog = (AggregateCatalog)container.Catalog;          catalog.Catalogs.Add(new AssemblyCatalog(fileName));          container.ComposeParts();      }      public T GetExport<T>(string name)      {          return container.GetExportedValue<T>(name);      }    }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表