I have some settings that I’d like to store in an external file of some sort, so that someone can change the settings without having to recompile the application:
Server: test
Username: abc
Password: 123
Server: dev
Username: abc
Password: def
Server: live
Username: g5g5g5
Password :a4a4a4
I know I can put them in app.config under <appSettings>, but the problem with that is that the data needs to be ‘grouped’ together and <appSettings> only supports plain key/value pairs.
I could put it into an external file as JSON, but that would involve either writing a JSON parser or downloading one, which is not very desirable for this application’s use case.
What other methods are there to store this information? Preferably using whatever is built into the .NET framework already and is easy to implement and understand for new developers.
You can create a class with your custom settings
e.g.
and save/load them to a file using the BinarySerializer, XmlSerializer, DataContractSerializer, or another serializer of your choice.
Since you want to edit with a text editor, DataContractSerialzier would be a good choice.
Here’s an example from MSDN showing how to serialize to a file
http://msdn.microsoft.com/en-us/library/bb675198.aspx