views:

43

answers:

2

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?

A: 

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

George Stocker
+2  A: 

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

Muad'Dib