public static void SaveSetting(this ApplicationSettingsBase settings, string settingName, object value) { if (!settings.HasSetting(settingName)) { return; } var val = Convert.ChangeType(value, value.GetType()); settings[settingName] = val; }
public static T LoadSetting <T>(this ApplicationSettingsBase settings, string settingName) { if (!settings.HasSetting(settingName)) { return(default(T)); } var val = settings[settingName]; return(Convert.ChangeType(val, typeof(T)).To <T>()); }
private static SettingsProperty GetOrAddSetting(this ApplicationSettingsBase settings, string settingName, Type settingType, object defaultValue) { return(settings.HasSetting(settingName) ? settings.GetSetting(settingName) : settings.AddUserSetting(settingName, settingType, defaultValue)); }