开发者

In C#, can one modify an application's configuration at runtime, and if so, how?

I'm writing an assembly, using C#, which will be accessed via it's COM interface.

Fo开发者_C百科r this reason it does not have a specific exe, and therefore no [appname].exe.config.

The assembly requires some application settings. Is there a way to modify the application settings at runtime, so that it doesn't require [appname].exe.config?


There is a way, but it is not all that easy.

The config mechanism in .NET is scoped by AppDomain. If you spawn your own child AppDomain you can specify where its config should be obtained from. All types/objects which you then load and execute in the child AppDomain can pick up their configuration from your specified custom config source.

Tools like NUnit use this technique to allow you to specify the config for the code being tested without having to put it into NUnit.exe.config.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜