/// <summary> /// Sets a setting /// </summary> /// <param name="key">The name (ID) of the setting</param> /// <param name="o">The object to save</param> /// <param name="level">The configuration level</param> protected void Set(string key, object o, ConfigLevel level = ConfigLevel.User) { object old; switch (level) { case ConfigLevel.Application: old = appconfig.ContainsKey(key) ? appconfig[key] : null; appconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; case ConfigLevel.User: old = userconfig.ContainsKey(key) ? userconfig[key] : null; userconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; case ConfigLevel.Instance: old = instconfig.ContainsKey(key) ? instconfig[key] : null; instconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; } }
/// <summary> /// Handles fetching of a value in the StringValues Dictionary /// </summary> /// <param name="defaultValue">Default Value to use if value is not found in the Settings Dictionary</param> /// <param name="name">Compiler Generated Name of Property</param> /// <returns>String Value for the dictionary</returns> public string GetString(string defaultValue = null, [CallerMemberName] string name = null) { if (name == null) { return(null); } return(StringValues.ContainsKey(name) ? StringValues[name] : defaultValue); }