/// <summary> /// Returns the value of the setting name <paramref name = "key" /> as a /// <c>T</c> instance. /// </summary> /// <typeparam name = "T">The type needed by the user.</typeparam> /// <param name = "key">The name of the setting.</param> /// <param name = "defaultValue">The default value.</param> /// <returns> /// returns the setting value as a <c>T</c> instance or <paramref name = "defaultValue" /> if the key does not exist. /// </returns> public T Get <T>(string key, T defaultValue) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } string result = null; if (_settings.ContainsKey(key)) { result = _settings[key]; } return((result == null) ? defaultValue : SettingConverter.GetTFromString <T>(result)); }
/// <summary> /// Sets the value of the setting name <paramref name = "key" />. If the setting /// does not exist, it is created. /// </summary> /// <typeparam name = "T">The type of the setting being saved.</typeparam> /// <param name = "key">The name of the setting.</param> /// <param name = "value">The value to save in this section.</param> public void Set <T>(string key, T value) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (_settings.ContainsKey(key)) { _settings[key] = SettingConverter.GetStringFromT(value); } else { _settings.Add(key, SettingConverter.GetStringFromT(value)); } PropertyChanged.Raise(this, new PropertyChangedEventArgs(key)); }