- Timestamp:
- 01/11/10 03:55:51 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 93 94 } 94 95 } 95 if (!oldKeyFound) throw new ArgumentException(" item not found");96 if (!oldKeyFound) throw new ArgumentException("Item not found"); 96 97 dict.Remove(oldKey); 97 98 dict.Add(GetKeyForItem(item), item); 99 OnPropertyChanged("Item[]"); 98 100 OnItemsReplaced(new TItem[] { item }, new TItem[] { item }); 99 101 } … … 139 141 public void Add(TItem item) { 140 142 dict.Add(GetKeyForItem(item), item); 143 OnPropertyChanged("Item[]"); 144 OnPropertyChanged("Count"); 141 145 OnItemsAdded(new TItem[] { item }); 142 146 } 143 147 public void AddRange(IEnumerable<TItem> collection) { 144 148 if (collection == null) throw new ArgumentNullException(); 145 foreach (TItem item in collection) 149 bool empty = true; 150 foreach (TItem item in collection) { 146 151 dict.Add(GetKeyForItem(item), item); 147 OnItemsAdded(collection); 152 empty = false; 153 } 154 if (!empty) { 155 OnPropertyChanged("Item[]"); 156 OnPropertyChanged("Count"); 157 OnItemsAdded(collection); 158 } 148 159 } 149 160 … … 152 163 if (TryGetValue(key, out item)) { 153 164 dict.Remove(key); 165 OnPropertyChanged("Item[]"); 166 OnPropertyChanged("Count"); 154 167 OnItemsRemoved(new TItem[] { item }); 155 168 return true; … … 159 172 public bool Remove(TItem item) { 160 173 if (dict.Remove(GetKeyForItem(item))) { 174 OnPropertyChanged("Item[]"); 175 OnPropertyChanged("Count"); 161 176 OnItemsRemoved(new TItem[] { item }); 162 177 return true; … … 171 186 items.Add(item); 172 187 } 173 if (items.Count > 0) 188 if (items.Count > 0) { 189 OnPropertyChanged("Item[]"); 190 OnPropertyChanged("Count"); 174 191 OnItemsRemoved(items); 192 } 175 193 } 176 194 public int RemoveAll(Predicate<TItem> match) { … … 181 199 182 200 public void Clear() { 183 TItem[] items = dict.Values.ToArray(); 184 dict.Clear(); 185 OnCollectionReset(new TItem[0], items); 201 if (dict.Count > 0) { 202 TItem[] items = dict.Values.ToArray(); 203 dict.Clear(); 204 OnPropertyChanged("Item[]"); 205 OnPropertyChanged("Count"); 206 OnCollectionReset(new TItem[0], items); 207 } 186 208 } 187 209 #endregion … … 257 279 CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems)); 258 280 } 281 282 [field: NonSerialized] 283 public event PropertyChangedEventHandler PropertyChanged; 284 protected virtual void OnPropertyChanged(string propertyName) { 285 if (PropertyChanged != null) 286 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 287 } 259 288 #endregion 260 289 }
Note: See TracChangeset
for help on using the changeset viewer.