The SettingsProperty
object for each user setting (or any setting) can be obtained through the Properties
collection on the Settings
class. You can then look at the DefaultValue
property to get a default value (the value before being set for a particular user. For example, if you'd normally access your property like this:
var value = Properties.Settings.Default.MySetting;
then you can get at the default value like this:
var defaultValue = Properties.Settings.Default.Properties["MySetting"].DefaultValue;
The default value is the one that you set in the settings editor in Visual studio.
Update:
I'm not aware of any other way of getting default values. To avoid the string property name, you could write an extension method to get the default value based on compiler-checked expression:
public static class SettingsExtensions
{
public static T GetSettingDefaultValue<T, T2>(this T2 settings,
Expression<Func<T2, T>> expression) where T2 : ApplicationSettingsBase
{
MemberExpression memberExpr = expression.Body as MemberExpression;
return (T)settings.Properties[memberExpr.Member.Name].DefaultValue;
}
}
And get the default value like this:
var defaultValue = Settings.Default.GetSettingDefaultValue(s => s.MySetting);