Changeset 2575 for trunk/sources/HeuristicLab.Collections
- Timestamp:
- 12/29/09 02:33:57 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Collections/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/IObservableCollection.cs
r2574 r2575 26 26 27 27 namespace HeuristicLab.Collections { 28 public interface IObservableCollection<T> : ICollection<T> {28 public interface IObservableCollection<T> : ICollection<T>, IDisposable { 29 29 event CollectionItemsChangedEventHandler<T> ItemsAdded; 30 30 event CollectionItemsChangedEventHandler<T> ItemsRemoved; -
trunk/sources/HeuristicLab.Collections/3.3/IObservableKeyedCollection.cs
r2574 r2575 26 26 27 27 namespace HeuristicLab.Collections { 28 public interface IObservableKeyedCollection<TKey, TItem> : IObservableCollection<TItem> , IDisposable{28 public interface IObservableKeyedCollection<TKey, TItem> : IObservableCollection<TItem> { 29 29 event CollectionItemsChangedEventHandler<TItem> ItemsReplaced; 30 30 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs
r2574 r2575 56 56 public ObservableCollection(IEnumerable<T> collection) { 57 57 list = new List<T>(collection); 58 OnItemsAdded(collection); 59 } 60 #endregion 61 62 #region Destructors 63 ~ObservableCollection() { 64 Dispose(false); 65 } 66 protected virtual void Dispose(bool disposing) { 67 if (disposing) { 68 Clear(); 69 } 70 } 71 public void Dispose() { 72 Dispose(true); 73 GC.SuppressFinalize(this); 58 74 } 59 75 #endregion -
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r2574 r2575 80 80 public ObservableDictionary(IDictionary<TKey, TValue> dictionary) { 81 81 dict = new Dictionary<TKey, TValue>(dictionary); 82 OnItemsAdded(dictionary); 82 83 } 83 84 public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer) { … … 86 87 public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) { 87 88 dict = new Dictionary<TKey, TValue>(dictionary, comparer); 89 OnItemsAdded(dictionary); 90 } 91 #endregion 92 93 #region Destructors 94 ~ObservableDictionary() { 95 Dispose(false); 96 } 97 protected virtual void Dispose(bool disposing) { 98 if (disposing) { 99 Clear(); 100 } 101 } 102 public void Dispose() { 103 Dispose(true); 104 GC.SuppressFinalize(this); 88 105 } 89 106 #endregion -
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 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs
r2574 r2575 70 70 public ObservableList(IEnumerable<T> collection) { 71 71 list = new List<T>(collection); 72 OnItemsAdded(GetIndexedItems()); 73 } 74 #endregion 75 76 #region Destructors 77 ~ObservableList() { 78 Dispose(false); 79 } 80 protected virtual void Dispose(bool disposing) { 81 if (disposing) { 82 Clear(); 83 } 84 } 85 public void Dispose() { 86 Dispose(true); 87 GC.SuppressFinalize(this); 72 88 } 73 89 #endregion
Note: See TracChangeset
for help on using the changeset viewer.