开发者

How to translate a config.ini file into C#.NET objects

config.ini:

[globalloads]
plugin.SWPlugin = 1
plugin.SWPlugin.params.1 = true
plugin.SWPlugin.params.2 = 10

[testz : globballoads]
plugin.SWPlugin.params.2 = 20
plugin.S开发者_StackOverflow中文版WAnotherPlugin = 1

Simple enough?

// load testz config and programmatically create this equivalent code:
SWPluginAbstract p = new SWPlugin(true, 20);
// go thru the loop and load the other plugin too
SWPluginAbstract p = new SWAnotherPlugin();

If a different config.ini setup is needed to do that, it's not a problem... I suspect I will need to use a reflection class of some sort? I'm new to the whole .NET thing


The recommended mechanism for storing settings is to define custom ConfigurationSection's w/ custom elements and collections. These can then be stored in machine.config, app.config and a few other places.

The easiest way to make these is with a Visual Studio add-in called "Configuration Section Designer" on CodePlex.com.

It's visual and does a good job of making configuration sections.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜