Пример #1
0
 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;
         }
     }
 }
Пример #2
0
        /// <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;
            }
        }
Пример #3
0
        /// <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);
        }