Esempio n. 1
0
 public void Add(CfgNodeValue <TK, TV> value)
 {
     lock (_lock)
     {
         AllItems.Add(value);
         if (!RepeatedItems.ContainsKey(value.Key))
         {
             if (SingleItems.ContainsKey(value.Key))
             {
                 RepeatedItems.Add(value.Key, new List <CfgNodeValue <TK, TV> > {
                     SingleItems[value.Key]
                 });
                 SingleItems.Remove(value.Key);
                 RepeatedItems[value.Key].Add(value);
             }
             else
             {
                 SingleItems.Add(value.Key, value);
             }
         }
         else
         {
             RepeatedItems[value.Key].Add(value);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Replaces ALL the elements that match in KEY and VALUE for the new one
        /// </summary>
        public void Replace(CfgNodeValue <TK, TV> oldKeyVal, CfgNodeValue <TK, TV> newKeyVal)
        {
            lock (_lock)
            {
                var index = AllItems.IndexOf(oldKeyVal);
                if (index >= 0)
                {
                    AllItems[index] = newKeyVal;

                    if (SingleItems.ContainsKey(oldKeyVal.Key))
                    {
                        if (oldKeyVal.Key.Equals(newKeyVal.Key))
                        {
                            SingleItems[oldKeyVal.Key] = newKeyVal;
                        }
                        else
                        {
                            SingleItems.Remove(oldKeyVal.Key);
                            SingleItems.Add(newKeyVal.Key, newKeyVal);
                        }
                    }
                    else
                    {
                        if (RepeatedItems.ContainsKey(oldKeyVal.Key))
                        {
                            if (oldKeyVal.Key.Equals(newKeyVal.Key))
                            {
                                for (var i = 0; i < RepeatedItems[oldKeyVal.Key].Count; i++)
                                {
                                    if (RepeatedItems[oldKeyVal.Key][i].Equals(oldKeyVal))
                                    {
                                        RepeatedItems[oldKeyVal.Key][i] = newKeyVal;
                                    }
                                }
                            }
                            else
                            {
                                Remove(oldKeyVal);
                                Add(newKeyVal);
                            }
                        }
                    }
                }
            }
        }