diff --git a/Nuclex.Support (PC).csproj b/Nuclex.Support (PC).csproj index 98c1ad2..e65c43f 100644 --- a/Nuclex.Support (PC).csproj +++ b/Nuclex.Support (PC).csproj @@ -65,10 +65,6 @@ - - false - AcquiringCollection - false ItemEventArgs @@ -304,4 +300,4 @@ --> - \ No newline at end of file + diff --git a/Nuclex.Support.build b/Nuclex.Support.build new file mode 100644 index 0000000..3c9f37c --- /dev/null +++ b/Nuclex.Support.build @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Collections/AcquiringCollection.cs b/Source/Collections/AcquiringCollection.cs deleted file mode 100644 index afe73e3..0000000 --- a/Source/Collections/AcquiringCollection.cs +++ /dev/null @@ -1,110 +0,0 @@ -#region CPL License -/* -Nuclex Framework -Copyright (C) 2002-2007 Nuclex Development Labs - -This library is free software; you can redistribute it and/or -modify it under the terms of the IBM Common Public License as -published by the IBM Corporation; either version 1.0 of the -License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -IBM Common Public License for more details. - -You should have received a copy of the IBM Common Public -License along with this library -*/ -#endregion - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; - -namespace Nuclex.Support.Collections { - - /// Generic collection of progressions - public class AcquiringCollection : Collection { - - /// - /// Initializes a new instance of the ObservableCollection class that is empty. - /// - public AcquiringCollection() : base() { } - - /// - /// Initializes a new instance of the ObservableCollection class as a wrapper - /// for the specified list. - /// - /// The list that is wrapped by the new collection. - /// - /// List is null. - /// - public AcquiringCollection(IList list) : base(list) { } - - /// Removes all elements from the Collection - protected override void ClearItems() { - OnClearing(); - - base.ClearItems(); - } - - /// - /// Inserts an element into the ProgressionCollection at the specified index - /// - /// - /// The object to insert. The value can be null for reference types. - /// - /// The zero-based index at which item should be inserted - protected override void InsertItem(int index, ItemType item) { - base.InsertItem(index, item); - - OnAdded(item); - } - - /// - /// Removes the element at the specified index of the ProgressionCollection - /// - /// The zero-based index of the element to remove - protected override void RemoveItem(int index) { - ItemType item = base[index]; - - base.RemoveItem(index); - - OnRemoved(item); - } - - /// Replaces the element at the specified index - /// - /// The new value for the element at the specified index. The value can be null - /// for reference types - /// - /// The zero-based index of the element to replace - protected override void SetItem(int index, ItemType item) { - ItemType oldItem = base[index]; - - base.SetItem(index, item); - - OnRemoved(oldItem); - OnAdded(item); - } - - /// Called when an item has been added to the collection - /// Item that has been added to the collection - protected virtual void OnAdded(ItemType item) { } - - /// Called when an item has been removed from the collection - /// Item that has been removed from the collection - protected virtual void OnRemoved(ItemType item) { } - - /// Called when the collection is being cleared - /// - /// Instead of calling the OnRemoved() method for each item in the collection when - /// it is being cleared, this variant only triggers the OnClearing() method - /// to allow the implementer some room for optimizations. - /// - protected virtual void OnClearing() { } - - } - -} // namespace Nuclex.Support.Collections diff --git a/Source/Collections/ObservableCollection.cs b/Source/Collections/ObservableCollection.cs index b485dc4..0022b0e 100644 --- a/Source/Collections/ObservableCollection.cs +++ b/Source/Collections/ObservableCollection.cs @@ -23,13 +23,36 @@ using System.Collections.ObjectModel; namespace Nuclex.Support.Collections { - /// Collection which fires events when items are added or removed - public class ObservableCollection : AcquiringCollection { + /// Generic collection of progressions + public class ObservableCollection : Collection { + + #region class ItemEventArgs + + /// Arguments class for events that need to pass a progression + public class ItemEventArgs : EventArgs { + + /// Initializes a new event arguments supplier + /// Item to be supplied to the event handler + public ItemEventArgs(ItemType item) { + this.item = item; + } + + /// Obtains the collection item the event arguments are carrying + public ItemType Item { + get { return this.item; } + } + + /// Item that's passed to the event handler + private ItemType item; + + } + + #endregion // class ItemEventArgs /// Raised when an item has been added to the collection - public event EventHandler> ItemAdded; + public event EventHandler ItemAdded; /// Raised when an item is removed from the collection - public event EventHandler> ItemRemoved; + public event EventHandler ItemRemoved; /// Raised the collection is about to be cleared public event EventHandler Clearing; @@ -43,25 +66,74 @@ namespace Nuclex.Support.Collections { /// for the specified list. /// /// The list that is wrapped by the new collection. - /// List is null. + /// + /// List is null. + /// public ObservableCollection(IList list) : base(list) { } + /// Removes all elements from the Collection + protected override void ClearItems() { + OnClearing(); + + base.ClearItems(); + } + + /// + /// Inserts an element into the ProgressionCollection at the specified index + /// + /// + /// The object to insert. The value can be null for reference types. + /// + /// The zero-based index at which item should be inserted + protected override void InsertItem(int index, ItemType item) { + base.InsertItem(index, item); + + OnAdded(item); + } + + /// + /// Removes the element at the specified index of the ProgressionCollection + /// + /// The zero-based index of the element to remove + protected override void RemoveItem(int index) { + ItemType item = base[index]; + + base.RemoveItem(index); + + OnRemoved(item); + } + + /// Replaces the element at the specified index + /// + /// The new value for the element at the specified index. The value can be null + /// for reference types + /// + /// The zero-based index of the element to replace + protected override void SetItem(int index, ItemType item) { + ItemType oldItem = base[index]; + + base.SetItem(index, item); + + OnRemoved(oldItem); + OnAdded(item); + } + /// Fires the 'ItemAdded' event /// Item that has been added to the collection - protected override void OnAdded(ItemType item) { + protected virtual void OnAdded(ItemType item) { if(ItemAdded != null) - ItemAdded(this, new ItemEventArgs(item)); + ItemAdded(this, new ItemEventArgs(item)); } /// Fires the 'ItemRemoved' event /// Item that has been removed from the collection - protected override void OnRemoved(ItemType item) { + protected virtual void OnRemoved(ItemType item) { if(ItemRemoved != null) - ItemRemoved(this, new ItemEventArgs(item)); + ItemRemoved(this, new ItemEventArgs(item)); } /// Fires the 'Clearing' event - protected override void OnClearing() { + protected virtual void OnClearing() { if(Clearing != null) Clearing(this, EventArgs.Empty); }