MEF example code_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > MEF example code

MEF example code

 2015/4/29 10:48:43  哨兵  程序员俱乐部  我要评论(0)
  • 摘要:publicinterfaceIObjectResolver{}publicclassObjectResolver:IObjectResolver{privateCompositionContainercontainer;publicObjectResolver(){container=newCompositionContainer(newAggregateCatalog());}publicvoidAddCatalogFile(stringfileName){if(!File.Exists
  • 标签:

 

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);
      }
    }
  • 相关文章
发表评论
用户名: 匿名