I would like to get some advise about getting and setting multiple values in one property. I have a lot of the same properties that get and set an int value from app settings, based on a selected profile (so the value will be retrieved from the app settings in the getter and in the setter the new value will be saved to the app settings).
Currently, all properties look like the following example code:
public int NumberValue
{
get
{
if (_profile == MainProfile.ProfileOne)
{
return AppSettings.NumberValue1;
}
else if(_profile == MainProfile.ProfileTwo)
{
return AppSettings.NumberValue2;
}
else
{
return AppSettings.NumberValue3;
}
}
set
{
if (_profile == MainProfile.ProfileOne)
{
AppSettings.NumberValue1 = value;
}
else if(_profile == MainProfile.ProfileTwo)
{
AppSettings.NumberValue2 = value;
}
else
{
AppSettings.NumberValue3 = value;
}
SaveAppSettings();
NotifyPropertyChanged();
}
}
I would like to know if there is an efficient way to rewrite these properties in a more efficient way.
FooProfileOne,FooProfileTwo... with a base class ofFooor interface ofIFoo?MainProfile? Is it an enum or a class ?ConfigurationManager.OpenExeConfiguration("xxxx.config");?