예제 #1
0
        private void OnInfoCardSubjectChanged(object sender, PropertyChangedRoutedEventArgs <IInfoCardSubject> e)
        {
            var oldSubject = e.OldValue;

            if (oldSubject == null)
            {
                return;
            }

            InfoCard infoCard;

            if (!_infoCardCache.TryGetValue(oldSubject, out infoCard))
            {
                return;
            }

            _infoCardCache.Remove(oldSubject);

            var newSubject = e.NewValue;

            if (newSubject != null)
            {
                _infoCardCache[newSubject] = infoCard;
            }
            else if (infoCard.IsOpen)
            {
                infoCard.Close();
            }
            else
            {
                RetireInfoCard(infoCard);
            }
        }
예제 #2
0
        /// <summary>
        /// It will clean the internal dictionaries from old references of buttons already disposed.
        /// </summary>
        private void CleanDeadReferences()
        {
            try
            {
                List <Button> toClean = new List <Button>();
                foreach (Button btn in NewProperties.Keys)
                {
                    if (btn.IsDisposed)
                    {
                        toClean.Add(btn);
                    }
                }
                foreach (Button btn in toClean)
                {
                    NewProperties.Remove(btn);
                }

                toClean.Clear();
                foreach (Button btn in EventsPatched.Keys)
                {
                    if (btn.IsDisposed)
                    {
                        toClean.Add(btn);
                    }
                }
                foreach (Button btn in toClean)
                {
                    EventsPatched.Remove(btn);
                }
            }
            catch
            {
            }
        }
예제 #3
0
 public static void Remove(object obj)
 {
     lock ( Sync )
     {
         DynamicFields.Remove(obj);
     }
 }
예제 #4
0
 public void Dispose()
 {
     if (slots != null)
     {
         slots.Remove(this);
     }
 }
 /// <summary>
 /// Removes a key and its value from the table.
 /// </summary>
 /// <param name="key">The key to remove.</param>
 /// <returns>
 ///    <c>true</c> if the key is found and removed; otherwise, <c>false</c>.
 /// </returns>
 public bool Remove(TKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return(_wrapped.Remove(key));
 }
        public void CanRemoveAnObjectThatWasAlreadyAdded()
        {
            object o = new object();
            WeakDictionary <object, object> dict = new WeakDictionary <object, object>();

            dict.Add("foo", o);
            dict.Remove("foo");
            object unused = dict["foo"];
        }
예제 #7
0
            /* Remove this reader from the cache, if present. */
            public void Purge(IndexReader r)
            {
                object readerKey = r.FieldCacheKey;

                lock (readerCache)
                {
                    readerCache.Remove(readerKey);
                }
            }
예제 #8
0
 private void RemoveItems(IEnumerable items)
 {
     foreach (var item in items)
     {
         var model = dataToVisual[item];
         dataToVisual.Remove(item);
         childrenRoot.Children.Remove(model);
     }
 }
예제 #9
0
        public void RemovingAKeyOfOneObjectDoesNotAffectOtherKeysForSameObject()
        {
            object o = new object();
            WeakDictionary <object, object> dict = new WeakDictionary <object, object>();

            dict.Add("foo1", o);
            dict.Add("foo2", o);
            dict.Remove("foo1");

            Assert.AreSame(o, dict["foo2"]);
        }
예제 #10
0
        public void RemovingAKeyDoesNotAffectOtherKeys()
        {
            object o1 = new object();
            object o2 = new object();
            WeakDictionary <object, object> dict = new WeakDictionary <object, object>();

            dict.Add("foo1", o1);
            dict.Add("foo2", o2);
            dict.Remove("foo1");

            Assert.AreSame(o2, dict["foo2"]);
        }
예제 #11
0
        //[ExpectedException(typeof(KeyNotFoundException))]
        public void CanRemoveAnObjectThatWasAlreadyAdded()
        {
            object o = new object();
            WeakDictionary <object, object> dict = new WeakDictionary <object, object>();

            dict.Add("foo", o);
            dict.Remove("foo");
            //object unused = dict["foo"];
            object unused = null;

            Assert.That(() => unused = dict["foo"],
                        Throws.TypeOf <KeyNotFoundException>());
        }
        /// <summary>
        /// Event handler for the Disposed event of a TreeView so it can be cleaned it.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private static void TreeView_Disposed(object sender, EventArgs e)
        {
            TreeView treeView = (TreeView)sender;

            if (NewProperties.ContainsKey(treeView))
            {
                NewProperties.Remove(treeView);
            }

            if (EventsPatched.ContainsKey(treeView))
            {
                EventsPatched.Remove(treeView);
            }
        }
        public void TestBasicOps()
        {
            WeakDictionary<string, string> wd = new WeakDictionary<string, string>();
            List<string> list = new List<string>();
            for (int i = 0; i < 100; i++)
            {
                list.Add(i.ToString());
            }

            foreach (string s in list)
            {
                wd.Add("k" + s, "v" + s);
            }
            foreach(string key in list)
            {
                Assert.AreEqual(wd["k"+key],"v"+key);
            }
            foreach (string key in list)
            {
                wd.Remove("k"+key);
            }
            Assert.AreEqual(0,wd.Count);


            foreach (string s in list)
            {
                wd.Add("k" + s, "v" + s);
            }
            foreach (string key in wd.Keys)
            {
                Assert.True(list.Contains(key.Substring(1)));
            }

            foreach(KeyValuePair<string,string> kv in wd)
            {
                Assert.True(list.Contains(kv.Key.Substring(1)));
                Assert.AreEqual(kv.Key.Substring(1), kv.Value.Substring(1));
            }
        }
예제 #14
0
파일: ListBoxHelper.cs 프로젝트: xxdoc/SKS
 /// <summary>
 /// Sets the SelectionMode for a control.
 /// </summary>
 /// <param name="lstBox">The control to set the SelectionMode.</param>
 /// <param name="mode">The selection mode to set.</param>
 public void SetSelectionMode(System.Windows.Forms.ListBox lstBox, System.Windows.Forms.SelectionMode mode)
 {
     lstBox.SelectionMode = mode;
     if ((mode == System.Windows.Forms.SelectionMode.MultiExtended) ||
         (mode == System.Windows.Forms.SelectionMode.MultiSimple))
     {
         if (!selectedIndexList.ContainsKey(lstBox))
         {
             selectedIndexList.Add(lstBox, 0);
             lstBox.DrawMode  = System.Windows.Forms.DrawMode.OwnerDrawFixed;
             lstBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(ListBox_DrawItem);
         }
     }
     else
     {
         if (selectedIndexList.ContainsKey(lstBox))
         {
             selectedIndexList.Remove(lstBox);
             lstBox.DrawMode  = DrawMode.Normal;
             lstBox.DrawItem -= new System.Windows.Forms.DrawItemEventHandler(ListBox_DrawItem);
         }
     }
 }
예제 #15
0
    /*************************************************************************************
    * EVENT
    *************************************************************************************/
    private static void OnEventObjectDestroy(EventObject aEventObject)
    {
        if (aEventObject == null)
        {
            return;
        }

        object dispatcher = aEventObject.Dispatcher;

        if (!_eventObjDict.ContainsKey(dispatcher))
        {
            return;
        }

        Dictionary <string, EventObject> eventObjectDictionary = _eventObjDict[dispatcher];

        eventObjectDictionary.Remove(aEventObject.EventName);

        if (eventObjectDictionary.Count <= 0)
        {
            _eventObjDict.Remove(dispatcher);
        }
    }
예제 #16
0
 /// <summary>
 /// Sets the SelectionMode for a control.
 /// </summary>
 /// <param name="lstBox">The control to set the SelectionMode.</param>
 /// <param name="mode">The selection mode to set.</param>
 public void SetSelectionMode(ListBox lstBox, SelectionMode mode)
 {
     lstBox.SelectionMode = mode;
     if ((mode == SelectionMode.MultiExtended) ||
         (mode == SelectionMode.MultiSimple))
     {
         if (!_SelectedIndexList.ContainsKey(lstBox))
         {
             _SelectedIndexList.Add(lstBox, 0);
             lstBox.DrawMode  = DrawMode.OwnerDrawFixed;
             lstBox.DrawItem += ListBox_DrawItem;
         }
     }
     else
     {
         if (_SelectedIndexList.ContainsKey(lstBox))
         {
             _SelectedIndexList.Remove(lstBox);
             lstBox.DrawMode  = DrawMode.Normal;
             lstBox.DrawItem -= ListBox_DrawItem;
         }
     }
 }
예제 #17
0
        public static AccessorClassLoader Get(Type type)
        {
            Assembly parent = type.Assembly;

            lock (writeLock)
            {
                List <KeyValuePair <Assembly, AccessorClassLoader> > toBeRemoved = null;
                foreach (KeyValuePair <Assembly, AccessorClassLoader> entry in accessClassLoaders)
                {
                    Assembly assembly = entry.Key;
                    if (assembly == null)
                    {
                        // Current ClassLoader is invalidated
                        if (toBeRemoved == null)
                        {
                            toBeRemoved = new List <KeyValuePair <Assembly, AccessorClassLoader> >();
                        }
                        toBeRemoved.Add(entry);
                        continue;
                    }
                    if (Object.ReferenceEquals(assembly, parent))
                    {
                        return(entry.Value);
                    }
                }
                if (toBeRemoved != null)
                {
                    foreach (KeyValuePair <Assembly, AccessorClassLoader> entry in toBeRemoved)
                    {
                        accessClassLoaders.Remove(entry);
                    }
                }
                AccessorClassLoader accessClassLoader = new AccessorClassLoader(parent);
                accessClassLoaders.Add(parent, accessClassLoader);
                return(accessClassLoader);
            }
        }
예제 #18
0
        public void RemovingANonExistantKeyDoesntThrow()
        {
            WeakDictionary <object, object> dict = new WeakDictionary <object, object>();

            dict.Remove("foo1");
        }