public TData this[TKey key] { get { if (m_data.ContainsKey(SerializeKey(key))) { return(m_data[SerializeKey(key)]); } else { return(Defaults(key)); } } set { if (value == null) { m_data.Remove(SerializeKey(key)); } else { m_data[SerializeKey(key)] = value; } ValueChanged.Execute(); } }
public void Load(XElement root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } if (m_suppressibleValueChanged.Suppressed) { throw new InternalLogicException("Can't load config while there are unsaved changes to config"); } using (SuppressCallback()) //The following block will modify the data but during a load that shouldn't trigger ValueChanged { var a = root.Element(m_name); m_data.Clear(); if (a != null) { foreach (var node in a.Elements("Element")) { ConfigParameter <TValue> t = m_nodeFactory(); t.Load(node); m_data.Add(t.Value); } } m_suppressibleValueChanged.Dispose(); //Pretend we haven't changed anything, by destroying the old callback and making a new one } m_suppressibleValueChanged = new SuppressibleAction(() => ValueChanged.Execute()); }
public ConfigParameterList(string name, Func <ConfigParameter <TValue> > nodeFactory) { m_name = name; m_suppressibleValueChanged = new SuppressibleAction(() => ValueChanged.Execute()); m_data.Modified += () => { m_suppressibleValueChanged.TryExecute(); }; m_nodeFactory = nodeFactory; }
public MapConfig(string nodeName, Func <KeyValuePair <TKey, TData>, KeyValuePair <string, string> > serialize, Func <KeyValuePair <string, string>, KeyValuePair <TKey, TData> > deserialize, Func <TKey, TData> defaults) { m_nodeName = nodeName; m_serialize = serialize; m_deserialize = deserialize; m_defaults = defaults; m_valueChanged = new SuppressibleAction(() => ValueChanged.Execute()); }
internal void Save() { ValueChanged.Execute(); }
internal void SetFilteredAssemblies(List <PluginAssembly> m_plugins) { m_filteredAssemblies.Clear(); m_filteredAssemblies.AddRange(m_plugins); ValueChanged.Execute(); }