I have an application written in c# 4.0 which uses the default Properties.Settings saved in a .config file alongside the exe file.
Then I have a new administration application to configure the settings for the other application.
I have figured out that i can use one of these to access the config file:
var map = new ExeConfigurationFileMap { ExeConfigFilename = configPath };
var config1 = ConfigurationManager.OpenMappedExeConfiguration(map, None);
var config2 = ConfigurationManager.OpenExeConfiguration(exePath);
I have further in mye administration application included a reference to the user application, and can therefore access the settings' default values with:
Settings settings = new Settings();
I somehow have to merge these two. Because if new properties have been added to the application's settings, and therefore is not present in the config file, I have to display the default value in the administration application.
When user chooses to save the configuration after editing them I have to write back to the configuration file. Newly added properties has to be added to the configuration file.
I think I can do this by looping through the properties in the config file and adding the values to the settings. After editing I loop through the settings and set values back to the config file. But isn't there any easier and more elegant way to do this?