I found an answer albeit a bit convoluted and requires going deep into the architecture of .NET, which isn't well documented. Although ApplicationSettingsBase and IApplicationSettingsProvider are decoupled, there is a bit of recoupling involved to make this work. The solution involves modifying the Settings or your own customized version like so:
[SettingsProvider(typeof(CustomSettingProviders.MySettingsProvider))]
internal sealed partial class Settings {
public Settings(string name)
{
this.Context.Add("Name", name);
}
Alternatively, you can get around making changes to this class by setting the Context before it's used like so:
settings.Context.Add("Name", "hello");
In the settings SetPropertyValues of the MySettingsProvider, you can actually grab the data and do something with it:
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
{
if (context.Contains("Name"))
ApplicationName = context["Name"].ToString();
To use the settings, simply instantiate the class with the parametrized constructor, or alternatively set the Context before using it:
var settings = new Properties.Settings("Hello") { Setting1 = "Hello, is anyone home!" }
// alternative: settings.Context.Add("Name", "hello");
settings.Save();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…