示例#1
0
 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();
     }
 }
示例#2
0
        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());
        }
示例#3
0
 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;
 }
示例#4
0
 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());
 }
示例#5
0
 internal void Save()
 {
     ValueChanged.Execute();
 }
示例#6
0
 internal void SetFilteredAssemblies(List <PluginAssembly> m_plugins)
 {
     m_filteredAssemblies.Clear();
     m_filteredAssemblies.AddRange(m_plugins);
     ValueChanged.Execute();
 }