/// <summary> /// Tries to gets the value of this settings key in the given profile, if it exists. /// </summary> /// <param name="value">The resulting value, if found</param> /// <param name="searchInParentProfile">If true, the settings service will look in the parent profile of the given profile if the settings key is not defined into it.</param> /// <param name="profile">The profile in which to look for the value. If <c>null</c>, it will look in the <see cref="SettingsGroup.CurrentProfile"/>.</param> /// <returns><c>true</c> if the value was found, <c>false</c> otherwise.</returns> public bool TryGetValue(out object value, bool searchInParentProfile = true, SettingsProfile profile = null) { profile = profile ?? Group.CurrentProfile; if (profile.GetValue(Name, out value, searchInParentProfile, false)) { return(true); } value = DefaultValueObject; return(false); }
/// <summary> /// Gets the value of this settings key in the given profile. /// </summary> /// <param name="searchInParentProfile">If true, the settings service will look in the parent profile of the given profile if the settings key is not defined into it.</param> /// <param name="profile">The profile in which to look for the value. If <c>null</c>, it will look in the <see cref="SettingsGroup.CurrentProfile"/>.</param> /// <param name="createInCurrentProfile">If true, the list will be created in the current profile, from the value of its parent profile.</param> /// <returns>The value of this settings key.</returns> /// <exception cref="KeyNotFoundException">No value can be found in the given profile matching this settings key.</exception> public T GetValue(bool searchInParentProfile = true, SettingsProfile profile = null, bool createInCurrentProfile = false) { object value; profile = profile ?? Group.CurrentProfile; if (profile.GetValue(Name, out value, searchInParentProfile, createInCurrentProfile)) { return((T)value); } throw new KeyNotFoundException("Settings key not found"); }
private void ChangeCurrentProfile(SettingsProfile oldProfile, SettingsProfile newProfile) { if (oldProfile == null) { throw new ArgumentNullException("oldProfile"); } if (newProfile == null) { throw new ArgumentNullException("newProfile"); } currentProfile = newProfile; lock (SettingsLock) { foreach (var key in settingsKeys) { object oldValue; oldProfile.GetValue(key.Key, out oldValue, true, false); object newValue; newProfile.GetValue(key.Key, out newValue, true, false); var oldList = oldValue as IList; var newList = newValue as IList; bool isDifferent; if (oldList != null && newList != null) { isDifferent = oldList.Count != newList.Count; for (int i = 0; i < oldList.Count && !isDifferent; ++i) { if (!Equals(oldList[i], newList[i])) { isDifferent = true; } } } else { isDifferent = !Equals(oldValue, newValue); } if (isDifferent) { newProfile.NotifyEntryChanged(key.Key); } } } // Changes have been notified, empty the list of modified settings. newProfile.ValidateSettingsChanges(); }
/// <summary> /// Tries to gets the value of this settings key in the given profile, if it exists. /// </summary> /// <param name="value">The resulting value, if found</param> /// <param name="searchInParentProfile">If true, the settings service will look in the parent profile of the given profile if the settings key is not defined into it.</param> /// <param name="profile">The profile in which to look for the value. If <c>null</c>, it will look in the <see cref="SettingsGroup.CurrentProfile"/>.</param> /// <returns><c>true</c> if the value was found, <c>false</c> otherwise.</returns> public bool TryGetValue(out T value, bool searchInParentProfile = true, SettingsProfile profile = null) { object obj; profile = profile ?? Group.CurrentProfile; if (profile.GetValue(Name, out obj, searchInParentProfile, false)) { try { value = (T)obj; return(true); } catch (Exception e) { // The cast exception will fallback to the value unfound result. e.Ignore(); } } value = DefaultValue; return(false); }
private void ChangeCurrentProfile(SettingsProfile oldProfile, SettingsProfile newProfile) { if (oldProfile == null) throw new ArgumentNullException("oldProfile"); if (newProfile == null) throw new ArgumentNullException("newProfile"); currentProfile = newProfile; foreach (var key in settingsKeys) { object oldValue; oldProfile.GetValue(key.Key, out oldValue, true, false); object newValue; newProfile.GetValue(key.Key, out newValue, true, false); var oldList = oldValue as IList; var newList = newValue as IList; bool isDifferent; if (oldList != null && newList != null) { isDifferent = oldList.Count != newList.Count; for (int i = 0; i < oldList.Count && !isDifferent; ++i) { if (!Equals(oldList[i], newList[i])) isDifferent = true; } } else { isDifferent = !Equals(oldValue, newValue); } if (isDifferent) { newProfile.NotifyEntryChanged(key.Key); } } // Changes have been notified, empty the list of modified settings. newProfile.ValidateSettingsChanges(); }
/// <summary> /// Determines whether the specified profile contains key (without checking parent profiles). /// </summary> /// <param name="profile">The profile.</param> /// <returns></returns> public bool ContainsKey(SettingsProfile profile) { object value; return(profile.GetValue(Name, out value, false, false)); }
/// <summary> /// Determines whether the specified profile contains key (without checking parent profiles). /// </summary> /// <param name="profile">The profile.</param> /// <returns></returns> public bool ContainsKey(SettingsProfile profile) { object value; return profile.GetValue(Name, out value, false, false); }
/// <summary> /// Tries to gets the value of this settings key in the given profile, if it exists. /// </summary> /// <param name="value">The resulting value, if found</param> /// <param name="searchInParentProfile">If true, the settings service will look in the parent profile of the given profile if the settings key is not defined into it.</param> /// <param name="profile">The profile in which to look for the value. If <c>null</c>, it will look in the <see cref="SettingsGroup.CurrentProfile"/>.</param> /// <returns><c>true</c> if the value was found, <c>false</c> otherwise.</returns> public bool TryGetValue(out object value, bool searchInParentProfile = true, SettingsProfile profile = null) { profile = profile ?? Group.CurrentProfile; if (profile.GetValue(Name, out value, searchInParentProfile, false)) { return true; } value = DefaultValueObject; return false; }
/// <summary> /// Gets the value of this settings key in the given profile. /// </summary> /// <param name="searchInParentProfile">If true, the settings service will look in the parent profile of the given profile if the settings key is not defined into it.</param> /// <param name="profile">The profile in which to look for the value. If <c>null</c>, it will look in the <see cref="SettingsGroup.CurrentProfile"/>.</param> /// <param name="createInCurrentProfile">If true, the list will be created in the current profile, from the value of its parent profile.</param> /// <returns>The value of this settings key.</returns> /// <exception cref="KeyNotFoundException">No value can be found in the given profile matching this settings key.</exception> public virtual object GetValue(bool searchInParentProfile = true, SettingsProfile profile = null, bool createInCurrentProfile = false) { object value; profile = profile ?? Group.CurrentProfile; if (profile.GetValue(Name, out value, searchInParentProfile, createInCurrentProfile)) { return value; } throw new KeyNotFoundException("Settings key not found"); }