Пример #1
0
        /// <summary>
        /// Will create a new ScalarPreference preference if is does not exist, otherwise it will return the cached.
        /// </summary>
        /// <param name="name">The name of the preference</param>
        /// <param name="value">The default value of the preference</param>
        /// <typeparam name="T">The type of the preference value</typeparam>
        /// <returns>The preference, never null</returns>
        public ScalarPreference <T> Preference <T>(string name, T value = default)
        {
            if (HasPreferenceCache <T>(name, out var result))
            {
                return(result);
            }

            result            = new ScalarPreference <T>(provider, name, value);
            derivations[name] = result;
            return(result);
        }
Пример #2
0
 private bool HasPreferenceCache <T>(string name, out ScalarPreference <T> preference)
 {
     preference = derivations[name] as ScalarPreference <T>;
     return(preference != null);
 }