【问题标题】:How to translate a config.ini file into C#.NET objects如何将 config.ini 文件转换为 C#.NET 对象
【发布时间】:2010-03-27 06:38:12
【问题描述】:

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

够简单吗?

// 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();

如果需要不同的 config.ini 设置来执行此操作,这不是问题...我怀疑我需要使用某种反射类?我是整个 .NET 的新手

【问题讨论】:

    标签: c# .net configuration object


    【解决方案1】:

    存储设置的推荐机制是使用自定义元素和集合定义自定义 ConfigurationSection。然后可以将它们存储在 machine.config、app.config 和其他一些地方。

    最简单的方法是使用 CodePlex.com 上名为“Configuration Section Designer”的 Visual Studio 加载项。

    它是可视化的,并且可以很好地制作配置部分。

    【讨论】:

    • 啊,我一直在寻找一个更简单的界面,让那些使用该程序但计算机编程经验有限的人能够在其中插入一行来自动加载插件等。它并不是一个您使用相同设置多次运行的程序,因此除了从 .ini 之类的简单文件之外的任何其他方式保存和加载它们都不是,呃.. 需要的。
    猜你喜欢
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2012-03-30
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    • 2010-12-07
    相关资源
    最近更新 更多