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); } }
/// <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 { } }
public static void Remove(object obj) { lock ( Sync ) { DynamicFields.Remove(obj); } }
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"]; }
/* Remove this reader from the cache, if present. */ public void Purge(IndexReader r) { object readerKey = r.FieldCacheKey; lock (readerCache) { readerCache.Remove(readerKey); } }
private void RemoveItems(IEnumerable items) { foreach (var item in items) { var model = dataToVisual[item]; dataToVisual.Remove(item); childrenRoot.Children.Remove(model); } }
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"]); }
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"]); }
//[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)); } }
/// <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); } } }
/************************************************************************************* * 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); } }
/// <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; } } }
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); } }
public void RemovingANonExistantKeyDoesntThrow() { WeakDictionary <object, object> dict = new WeakDictionary <object, object>(); dict.Remove("foo1"); }