Changeset 2574 for trunk/sources/HeuristicLab.Collections/3.3
- Timestamp:
- 12/28/09 21:38:15 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Collections/3.3
- Files:
-
- 4 added
- 4 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj
r2573 r2574 49 49 </ItemGroup> 50 50 <ItemGroup> 51 <Compile Include="IObservableKeyedCollection.cs" /> 52 <Compile Include="IObservableList.cs" /> 53 <Compile Include="IObservableCollection.cs" /> 54 <Compile Include="IObservableDictionary.cs" /> 51 55 <Compile Include="ObservableKeyedCollectionBase.cs" /> 52 <Compile Include="IndexedCollectionChangedEventsBase.cs" />53 56 <Compile Include="ObservableCollection.cs" /> 54 <Compile Include="IIndexedCollectionChangedEvents.cs" />55 57 <Compile Include="IndexedItem.cs" /> 56 <Compile Include="CollectionChangedEventsBase.cs" />57 58 <Compile Include="ObservableList.cs" /> 58 59 <Compile Include="CollectionItemsChangedEventArgs.cs" /> 59 60 <Compile Include="CollectionItemsChangedEventHandler.cs" /> 60 <Compile Include="ICollectionChangedEvents.cs" />61 61 <Compile Include="HeuristicLabCollectionsPlugin.cs" /> 62 62 <Compile Include="ObservableDictionary.cs" /> -
trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs
r2573 r2574 30 30 namespace HeuristicLab.Collections { 31 31 [Serializable] 32 public class ObservableCollection<T> : CollectionChangedEventsBase<T>, ICollection<T> {32 public class ObservableCollection<T> : IObservableCollection<T> { 33 33 [Storable] 34 34 private List<T> list; … … 158 158 } 159 159 #endregion 160 161 #region Events 162 [field: NonSerialized] 163 public event CollectionItemsChangedEventHandler<T> ItemsAdded; 164 protected virtual void OnItemsAdded(IEnumerable<T> items) { 165 if (ItemsAdded != null) 166 ItemsAdded(this, new CollectionItemsChangedEventArgs<T>(items)); 167 } 168 169 [field: NonSerialized] 170 public event CollectionItemsChangedEventHandler<T> ItemsRemoved; 171 protected virtual void OnItemsRemoved(IEnumerable<T> items) { 172 if (ItemsRemoved != null) 173 ItemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items)); 174 } 175 176 [field: NonSerialized] 177 public event CollectionItemsChangedEventHandler<T> CollectionReset; 178 protected virtual void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) { 179 if (CollectionReset != null) 180 CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems)); 181 } 182 #endregion 160 183 } 161 184 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r2573 r2574 30 30 namespace HeuristicLab.Collections { 31 31 [Serializable] 32 public class ObservableDictionary<TKey, TValue> : CollectionChangedEventsBase<KeyValuePair<TKey, TValue>>, IDictionary<TKey, TValue> {32 public class ObservableDictionary<TKey, TValue> : IObservableDictionary<TKey, TValue> { 33 33 [Storable] 34 34 private Dictionary<TKey, TValue> dict; … … 156 156 } 157 157 #endregion 158 159 #region Events 160 [field: NonSerialized] 161 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded; 162 protected virtual void OnItemsAdded(IEnumerable<KeyValuePair<TKey, TValue>> items) { 163 if (ItemsAdded != null) 164 ItemsAdded(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items)); 165 } 166 167 [field: NonSerialized] 168 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved; 169 protected virtual void OnItemsRemoved(IEnumerable<KeyValuePair<TKey, TValue>> items) { 170 if (ItemsRemoved != null) 171 ItemsRemoved(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items)); 172 } 173 174 [field: NonSerialized] 175 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced; 176 protected virtual void OnItemsReplaced(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) { 177 if (ItemsReplaced != null) 178 ItemsReplaced(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems)); 179 } 180 181 [field: NonSerialized] 182 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset; 183 protected virtual void OnCollectionReset(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) { 184 if (CollectionReset != null) 185 CollectionReset(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems)); 186 } 187 #endregion 158 188 } 159 189 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs
r2573 r2574 30 30 namespace HeuristicLab.Collections { 31 31 [Serializable] 32 public abstract class ObservableKeyedCollectionBase<TKey, TItem> : CollectionChangedEventsBase<TItem>, ICollection<TItem> {32 public abstract class ObservableKeyedCollectionBase<TKey, TItem> : IObservableKeyedCollection<TKey, TItem> { 33 33 [Storable] 34 34 private Dictionary<TKey, TItem> dict; … … 76 76 foreach (TItem item in collection) 77 77 AddItem(item); 78 } 79 #endregion 80 81 #region Destructors 82 ~ObservableKeyedCollectionBase() { 83 Dispose(false); 84 } 85 protected virtual void Dispose(bool disposing) { 86 if (disposing) { 87 Clear(); 88 } 89 } 90 public void Dispose() { 91 Dispose(true); 92 GC.SuppressFinalize(this); 78 93 } 79 94 #endregion … … 232 247 } 233 248 #endregion 249 250 #region Events 251 [field: NonSerialized] 252 public event CollectionItemsChangedEventHandler<TItem> ItemsAdded; 253 protected virtual void OnItemsAdded(IEnumerable<TItem> items) { 254 if (ItemsAdded != null) 255 ItemsAdded(this, new CollectionItemsChangedEventArgs<TItem>(items)); 256 } 257 258 [field: NonSerialized] 259 public event CollectionItemsChangedEventHandler<TItem> ItemsRemoved; 260 protected virtual void OnItemsRemoved(IEnumerable<TItem> items) { 261 if (ItemsRemoved != null) 262 ItemsRemoved(this, new CollectionItemsChangedEventArgs<TItem>(items)); 263 } 264 265 [field: NonSerialized] 266 public event CollectionItemsChangedEventHandler<TItem> ItemsReplaced; 267 protected virtual void OnItemsReplaced(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) { 268 if (ItemsReplaced != null) 269 ItemsReplaced(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems)); 270 } 271 272 [field: NonSerialized] 273 public event CollectionItemsChangedEventHandler<TItem> CollectionReset; 274 protected virtual void OnCollectionReset(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) { 275 if (CollectionReset != null) 276 CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems)); 277 } 278 #endregion 234 279 } 235 280 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs
r2573 r2574 30 30 namespace HeuristicLab.Collections { 31 31 [Serializable] 32 public class ObservableList<T> : I ndexedCollectionChangedEventsBase<IndexedItem<T>>, IList<T> {32 public class ObservableList<T> : IObservableList<T> { 33 33 [Storable] 34 34 private List<T> list; … … 45 45 get { return ((ICollection<T>)list).IsReadOnly; } 46 46 } 47 bool ICollection<IndexedItem<T>>.IsReadOnly { 48 get { return ((ICollection<T>)list).IsReadOnly; } 49 } 47 50 48 51 public T this[int index] { … … 78 81 return list.Contains(item); 79 82 } 83 public bool Contains(IndexedItem<T> item) { 84 return list[item.Index].Equals(item.Value); 85 } 80 86 81 87 public int IndexOf(T item) { … … 148 154 list.Add(item); 149 155 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) }); 156 } 157 public void Add(IndexedItem<T> item) { 158 list.Insert(item.Index, item.Value); 159 OnItemsAdded(new IndexedItem<T>[] { item }); 150 160 } 151 161 public void AddRange(IEnumerable<T> collection) { … … 183 193 return false; 184 194 } 195 public bool Remove(IndexedItem<T> item) { 196 if (list[item.Index].Equals(item.Value)) { 197 list.RemoveAt(item.Index); 198 OnItemsRemoved(new IndexedItem<T>[] { item }); 199 return true; 200 } 201 return false; 202 } 185 203 public int RemoveAll(Predicate<T> match) { 186 204 if (match == null) throw new ArgumentNullException(); … … 254 272 list.CopyTo(array, arrayIndex); 255 273 } 274 void ICollection<IndexedItem<T>>.CopyTo(IndexedItem<T>[] array, int arrayIndex) { 275 IndexedItem<T>[] items = GetIndexedItems(); 276 items.CopyTo(array, arrayIndex); 277 } 256 278 public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter) { 257 279 return list.ConvertAll<TOutput>(converter); … … 275 297 return ((IEnumerable<T>)list).GetEnumerator(); 276 298 } 299 IEnumerator<IndexedItem<T>> IEnumerable<IndexedItem<T>>.GetEnumerator() { 300 int index = -1; 301 foreach (T item in list) { 302 index++; 303 yield return new IndexedItem<T>(index, item); 304 } 305 } 277 306 IEnumerator IEnumerable.GetEnumerator() { 278 307 return ((IEnumerable)list).GetEnumerator(); … … 283 312 public void TrimExcess() { 284 313 list.TrimExcess(); 314 } 315 #endregion 316 317 #region Events 318 [field: NonSerialized] 319 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded; 320 protected virtual void OnItemsAdded(IEnumerable<IndexedItem<T>> items) { 321 if (ItemsAdded != null) 322 ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items)); 323 } 324 325 [field: NonSerialized] 326 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved; 327 protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) { 328 if (ItemsRemoved != null) 329 ItemsRemoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items)); 330 } 331 332 [field: NonSerialized] 333 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced; 334 protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { 335 if (ItemsReplaced != null) 336 ItemsReplaced(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems)); 337 } 338 339 [field: NonSerialized] 340 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved; 341 protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { 342 if (ItemsMoved != null) 343 ItemsMoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems)); 344 } 345 346 [field: NonSerialized] 347 public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset; 348 protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { 349 if (CollectionReset != null) 350 CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems)); 285 351 } 286 352 #endregion
Note: See TracChangeset
for help on using the changeset viewer.