Search code examples
c#application-settings

Save Dictionary in application settings


I would like to do something like this :

app.config :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
   <setting1> 
  <add key ="key1" value ="value1"/>
  <add key ="key2" value ="value2"/>
</setting1>
<setting2>
  <add key ="key1" value ="value1"/>
  <add key ="key2" value ="value2"/>
</setting2>

my.cs:

Configuration config =
                    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var appSettings = config.AppSettings;

Assert.equals(appSettings.Settings["setting1"]["key1"] == "value1");
Assert.equals(appSettings.Settings["setting1"]["key2"] == "value2");
Assert.equals(appSettings.Settings["setting2"]["key1"] == "value1");
Assert.equals(appSettings.Settings["setting2"]["key2"] == "value2");

could I in any way receive similar behavior?

Thank You !


Solution

  • You can write your own configuration section - there are many tutorials around.