I have a set of settings that I essentially need two copies of. There are two versions of a configuration that a user can switch between.
Normally I can access the settings with Properties.Settings.Default, but is there a way to have:
Properties.Settings.Conf1
Properties.Settings.Conf2
That way I can make a generic accessor with a single if statement
Properties.Settings setting;
if (isItConf1)
{
setting = Properties.Settings.Conf1;
}
else
{
setting = Properties.Settings.Conf2;
}
Then I can use the settings in my local variable instead of needing an if statement every time I want to use a value in those settings. Whether that means using two different settings files with the same fields, or just having to duplicate the lines with some kind of prefix to the field names. Both of which seem very inefficient.
EDIT:
I tried making a manual settings file with the same format but with two ApplicatonSettingsBase fields and a built in way to select which one I was accessing:
internal sealed class Bins : global::System.Configuration.ApplicationSettingsBase
{
private static Bins _bins1 = ((Bins)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Bins())));
private static Bins _bins2 = ((Bins)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Bins())));
private static Bins _activeBinSettings;
public static Bins ActiveBinSettings
{
get { return _activeBinSettings; }
set { _activeBinSettings = value; }
}
public static Bins Bins1
{
get { return _bins076; }
set { _bins076 = value; }
}
public static Bins Bins2
{
get { return _bins086; }
set { _bins086 = value; }
}
public static void SetBinType(ChipBase chip)
{
if(chip == ChipBase.ESS076)
{
_activeBinSettings = _bins1;
}
else
{
_activeBinSettings = _bins2;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("1")]
public int GoodBin
{
get
{
return ((int)(this["GoodBin"]));
}
set
{
this["GoodBin"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("1")]
public int BadBin
{
get
{
return ((int)(this["BadBin"]));
}
set
{
this["BadBin"] = value;
}
}
}
This works fine during run-time. It has the correct values when switching between bins1 and bins2, but the save() function only ever saves one set of data unfortunately. So when the application is restarted, it only ever saved the latest set of data to the user.config file.
Next step is to just accept having to have two settings files and I'll build a bit of a wrapper class to simplify which one I'm accessing.