MEF插件界面配置

public T GetConfig<T>(string sectionName) where T : ConfigurationSection
{
  try
  {
    Assembly assembly = typeof(T).Assembly;
    string directory = Path.GetDirectoryName(assembly.CodeBase);
    string filename = Path.GetFileName(assembly.CodeBase);
    string assemblyPath = Path.Combine(directory, filename);
    var config = ConfigurationManager.OpenExeConfiguration(new Uri(assemblyPath).LocalPath);
    return config.GetSection(sectionName) as T; ;
  }
  catch (Exception ex)
  {
    return null;
  }
}

  若一些公共的dll既在主文件目录又在插件目录则需要删除插件目录中的,在主程序配置文件中加入

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Inspectors"/>
    </assemblyBinding>
  </runtime>

  

posted on 2012-10-29 10:54  beastplus  阅读(208)  评论(0编辑  收藏  举报

导航