In my post I details how you can create an application settings class to read application settings and read/write user settings in a simple and consistent manner. But there’s more…
By default the user scoped properties are stored in a user.config file in the user’s profile. But we can actually customise where/how the settings are persisted by implementing code in a class derived from the SettingsProvider class. Firstly we need to apply the following
[SettingsProvider(typeof(MySettingsProvider))]
to the ApplicationSettingsBase derived class (in my previous post this would look like)
[SettingsProvider(typeof(ConfigurationSettingsProvider))] public sealed class ConfigurationSettings : ApplicationSettingsBase { // properties }
Next we obviously need to implement the ConfigurationSettingsProvider. In fact Microsoft implemented this to create the LocalFileSettingsProvider class which by default is applied to our settings class (allowing us to read from the app.config and persist to the user.config).
By overriding methods such as Initialize, GetPropertyValues and SetPropertyValues we can get our settings from our own mechanism, for example a web service and persist changes back to the web service.