Search code examples
.netfile-format

What's the best way to store grouped key value pairs in a file?


Currently I just have a file like this that I manually parse into a Dictionary:

str1=Hello
str2=World

This is no longer practical for several reasons:

  • I need lists of strings that I can access by index
  • I want to split the key value pairs into groups

I consider using XML now because:

  • Good for key value pairs and groups
  • I could use classes and serialize them, eliminating spelling errors

But (assuming I use serialized classes):

  • I would have to create a lot of new classes to map the document structure
  • Dictionaries need to be cared for specially because the can't usually be serialized

Do you recommend this approach? Should I use the XmlDocument class instead? Is there some other format that has free libraries for .net?

I want to use this for localizing an application.


Solution

  • .NET has pretty solid Resource-based support for localization, so you might look into that.

    If you really want to invent your own resource storage format, I'd suggest you to look more closely at JSON as serialization format (there are plenty of .NET libraries to handle it) or at YAML (not sure if there are decent .NET parsers): they both are much simpler on the eye (if that's what you're after).