为DLL配置文件 [英] configuring file for DLLs

查看:154
本文介绍了为DLL配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,它在运行时从应用程序的根目录加载我们的自定义DLL(这些DLL正在实现某些接口),并通过反射执行方法.

We are having application which load our custom DLLs (these DLLs are implementing some interface) on runtime from the root of the application and execute a method through reflection.

如果自定义DLL必须从配置文件中读取一些值,那么我们必须将这些配置设置复制到主应用程序的app.config文件中.

If custom DLL have to read some value from config files then we have to copy these config settings into app.config file of the main application.

有没有办法使每个自定义DLL具有自己的名为.config的配置文件并从该文件本身读取其配置设置.

Is there any way where each custom DLL will have own configuring file named .config and read its configuration settings from this files itself.

推荐答案

如果您使用的是.NET 2.0或更高版本,则可以手动告诉配置系统从所需的任何配置文件中加载设置.

If you're on .NET 2.0 or higher, you can manually tell the Configuration system to load the settings from any config file you want.

ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap();
exeMap.ExeConfigFilename = "C:\Application\Default.config";

Configuration exeConfig = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None);

现在,您有了自定义的"Config"对象,可以对其进行聚会! :-)通过调用exeConfig.GetSection()或您喜欢的任何内容来加载整个节.

Now you have your custom "Config" object and you can party on it! :-) Load a whole section by calling exeConfig.GetSection() or whatever you like.

还可以在CodeProject的.NET 2.0配置系统上查看这个出色的三部分系列-强烈建议!

Also check out this excellent three-part series on .NET 2.0 configuration system on CodeProject - highly recommended!

  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

马克

这篇关于为DLL配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆