/// <summary> /// Registers an entry that has not been registered before. /// </summary> /// <param name="entry">The entry to register.</param> internal void RegisterEntry(SettingsEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } Settings.Add(entry.Name, entry); }
internal static void RegisterSettingsKey(UFile name, object defaultValue, SettingsKey settingsKey) { SettingsKeys.Add(name, settingsKey); var entry = SettingsEntry.CreateFromValue(DefaultProfile, name, defaultValue); DefaultProfile.RegisterEntry(entry); // Ensure that the value is converted to the key type in each loaded profile. foreach (var profile in Profiles.Where(x => x != DefaultProfile)) { if (profile.Settings.TryGetValue(name, out entry)) { var convertedValue = settingsKey.ConvertValue(entry.Value); entry = SettingsEntry.CreateFromValue(profile, name, convertedValue); profile.Settings[name] = entry; } } }
/// <summary> /// Gets the settings value that matches the given name. /// </summary> /// <param name="name">The name of the <see cref="SettingsEntry"/> to fetch.</param> /// <param name="value">The resulting value if the name is found, <c>null</c> otherwise.</param> /// <param name="searchInParent">Indicates whether to search in the parent profile, if the name is not found in this profile.</param> /// <param name="createInCurrentProfile">If true, the list will be created in the current profile, from the value of its parent profile.</param> /// <returns><c>true</c> if an entry matching the name is found, <c>false</c> otherwise.</returns> internal bool GetValue(UFile name, out object value, bool searchInParent, bool createInCurrentProfile) { if (name == null) { throw new ArgumentNullException("name"); } SettingsEntry entry = GetEntry(name, searchInParent, createInCurrentProfile); if (entry != null) { value = entry.Value; return(true); } value = null; return(false); }
/// <summary> /// Set the value of the entry that match the given name. /// </summary> /// <param name="name">The name to match.</param> /// <param name="value">The value to set.</param> internal void SetValue(UFile name, object value) { if (name == null) { throw new ArgumentNullException("name"); } SettingsEntry entry; if (!Settings.TryGetValue(name, out entry)) { entry = SettingsEntry.CreateFromValue(this, name, value); Settings[name] = entry; } else { Settings[name].Value = value; } }
/// <summary> /// Gets the <see cref="SettingsEntry"/> that matches the given name. /// </summary> /// <param name="name">The name of the <see cref="SettingsEntry"/> to fetch.</param> /// <param name="searchInParent">Indicates whether to search in the parent profile, if the name is not found in this profile.</param> /// <param name="createInCurrentProfile"></param> /// <returns>An instance of <see cref="SettingsEntry"/> that matches the name, or <c>null</c>.</returns> private SettingsEntry GetEntry(UFile name, bool searchInParent, bool createInCurrentProfile) { if (name == null) { throw new ArgumentNullException("name"); } SettingsEntry entry; if (Settings.TryGetValue(name, out entry)) { return(entry); } if (createInCurrentProfile) { entry = parentProfile.GetEntry(name, true, false); entry = SettingsEntry.CreateFromValue(this, name, entry.Value); RegisterEntry(entry); return(entry); } return(parentProfile != null && searchInParent?parentProfile.GetEntry(name, true, false) : null); }