/// <summary> /// Returns the value corresponding to key in the preference file if it exists. /// </summary> /// <typeparam name="T">Value type</typeparam> /// <param name="key">The key</param> /// <param name="defaultValue">The default value.</param> /// <returns>Value corresponding to key or default value</returns> public static T Get <T>(string key, T defaultValue) { CommonPair <string, object> item = _data.Find(x => x.Key == key); if (item == null) { return(defaultValue); } return((T)item.Value); }
/// <summary> /// Sets the value of the preference identified by key. /// </summary> /// <param name="key">The key</param> /// <param name="value">The value</param> public static void Set(string key, object value) { CommonPair <string, object> item = _data.Find(x => x.Key == key); if (item == null) { _data.Add(new CommonPair <string, object>(key, value)); } else { item.Value = value; } Save(); }
// Searches layout element by specified path private static UiLayoutElement GetElement(string path) { CommonPair <string, UiLayoutElement> pair = _elements.Find(x => x.Key == path); return(pair != null ? pair.Value : null); }