I'm writing a new C# application which will make heavy use of a configuration file. My requirements are:
- Human readable
- Name value pairs
- Hierarchical
- [Updatable by application]
Um, to transla开发者_运维技巧te: 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:
- XML. Not sufficiently human readable.
- INI file. Not hierarchal
- JSON.
- 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?
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
I use custom configuration files when I need to do something like that. Here's how I did it.
精彩评论