- Timestamp:
- 12/29/09 02:33:57 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs
r2574 r2575 66 66 dict = new Dictionary<TKey, TItem>(); 67 67 foreach (TItem item in collection) 68 AddItem(item); 68 dict.Add(GetKeyForItem(item), item); 69 OnItemsAdded(collection); 69 70 } 70 71 protected ObservableKeyedCollectionBase(int capacity, IEqualityComparer<TKey> comparer) { … … 75 76 dict = new Dictionary<TKey, TItem>(comparer); 76 77 foreach (TItem item in collection) 77 AddItem(item); 78 dict.Add(GetKeyForItem(item), item); 79 OnItemsAdded(collection); 78 80 } 79 81 #endregion … … 150 152 151 153 #region Manipulation 152 p rotected virtual void AddItem(TItem item) {154 public void Add(TItem item) { 153 155 dict.Add(GetKeyForItem(item), item); 154 }155 public void Add(TItem item) {156 AddItem(item);157 156 OnItemsAdded(new TItem[] { item }); 158 157 } … … 160 159 if (collection == null) throw new ArgumentNullException(); 161 160 foreach (TItem item in collection) 162 AddItem(item);161 dict.Add(GetKeyForItem(item), item); 163 162 OnItemsAdded(collection); 164 163 } 165 164 166 protected virtual bool RemoveItem(TItem item) {167 return dict.Remove(GetKeyForItem(item));168 }169 165 public bool Remove(TKey key) { 170 166 TItem item; 171 167 if (TryGetValue(key, out item)) { 172 RemoveItem(item);168 dict.Remove(key); 173 169 OnItemsRemoved(new TItem[] { item }); 174 170 return true; … … 177 173 } 178 174 public bool Remove(TItem item) { 179 if ( RemoveItem(item)) {175 if (dict.Remove(GetKeyForItem(item))) { 180 176 OnItemsRemoved(new TItem[] { item }); 181 177 return true; … … 187 183 List<TItem> items = new List<TItem>(); 188 184 foreach (TItem item in collection) { 189 if ( RemoveItem(item))185 if (dict.Remove(GetKeyForItem(item))) 190 186 items.Add(item); 191 187 } … … 199 195 } 200 196 201 protected virtual void ClearItems() {202 dict.Clear();203 }204 197 public void Clear() { 205 198 TItem[] items = dict.Values.ToArray(); 206 ClearItems();199 dict.Clear(); 207 200 OnCollectionReset(new TItem[0], items); 208 201 }
Note: See TracChangeset
for help on using the changeset viewer.