C# 有什么好的配置文件工具

发布于 2024-09-28 07:28:11 字数 565 浏览 0 评论 0原文

我正在编写一个新的 C# 应用程序,它将大量使用配置文件。我的要求是:

  1. 人类可读的
  2. 名称值
  3. 对 分层
  4. [可由应用程序更新]

嗯,翻译一下:我想定义一个对象以及与该对象关联的一组配置参数。配置参数可以是名称值对或另一个对象,并附加其自己的属性:

module "db" { 主机:“db.example.com”; 编码器“zip”{ 压缩:10; } 我不太致力于要求 4,但

确实考虑到我希望应用程序更新设置并将其写回配置文件。

我知道以下选项:

  1. XML。人类可读性不够。
  2. INI 文件。不是分层
  3. JSON。
  4. YAML。

JSON 和 YAML 似乎值得研究。

建议使用这些进行配置吗?我可以考虑使用任何替代工具吗?

至于将应用程序所做的更改持久保存到配置文件中,我知道 JSON 和 YAML 可以做到这一点,但是可以在保存原始人工编辑版本中可能存在的注释的同时执行此操作吗?

I'm writing a new C# application which will make heavy use of a configuration file. My requirements are:

  1. Human readable
  2. Name value pairs
  3. Hierarchical
  4. [Updatable by application]

Um, to translate: I want to define an object and a set of configuration parameters associated with that object. The configuration parameters may be name value pairs or another object, with it's own attributes attached:

module "db" {
host: "db.example.com";
encoder "zip" {
compression: 10;
}
}

I'm less committed to requirement 4, but do consider that I would like the application to update a setting and write it back to the configuration file.

I am aware of the following options:

  1. XML. Not sufficiently human readable.
  2. INI file. Not hierarchal
  3. JSON.
  4. YAML.

JSON and YAML seem worth investigating.

Advise on using these for configuration? Any alternate tools I may want to consider?

As for persisting changes made by the application back to the config file I know that JSON and YAML can do this but can either do this WHILE saving comments which may have been in the original human edited version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Oo萌小芽oO 2024-10-05 07:28:11

重建轮子没有意义。为什么不直接使用内置的配置 API?它使用 XML,因此您可以根据需要在运行时手动编辑。 IDE 中有一个内置编辑器,可在构建时进行编辑。

这里有来自 MSDN 的更多内容

No sense in rebuilding the wheel. Why not just use the built-in configuration API? It uses XML, so you can edit by hand at run-time if you want to. there is a built-in editor in the IDE to edit at build-time.

here is more from MSDN

骄兵必败 2024-10-05 07:28:11

当我需要做类似的事情时,我使用自定义配置文件。 这是我的做法。

I use custom configuration files when I need to do something like that. Here's how I did it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文