简体   繁体   English

如何将config.ini文件转换为C#.NET对象

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

config.ini: config.ini:

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

[testz : globballoads]
plugin.SWPlugin.params.2 = 20
plugin.SWAnotherPlugin = 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? 如果需要使用不同的config.ini设置,那不是问题...我怀疑我需要使用某种反射类吗? I'm new to the whole .NET thing 我是整个.NET的新手

The recommended mechanism for storing settings is to define custom ConfigurationSection's w/ custom elements and collections. 推荐的存储设置机制是定义自定义ConfigurationSection的w /自定义元素和集合。 These can then be stored in machine.config, app.config and a few other places. 然后可以将它们存储在machine.config,app.config和其他一些地方。

The easiest way to make these is with a Visual Studio add-in called " Configuration Section Designer " on CodePlex.com. 最简单的方法是使用CodePlex.com上的Visual Studio加载项“ Configuration Section Designer ”。

It's visual and does a good job of making configuration sections. 它是可视的,并且在制作配置节方面做得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM