Extended to IObservableCollection interface with an ItemsCleared event so subscribers observing the collection only to trigger 'Changed' events (versus subscribers observing the collection to wire/unwire themselves from the collection's items) can make use of the collection

git-svn-id: file:///srv/devel/repo-conversion/nusu@182 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-10-12 19:19:58 +00:00
parent d5293d8cb9
commit 655ae7ab10
5 changed files with 54 additions and 38 deletions

View file

@ -39,6 +39,8 @@ namespace Nuclex.Support.Collections {
/// to process the clearing of the entire collection as a special operation.
/// </remarks>
public event EventHandler Clearing;
/// <summary>Raised when the collection has been cleared</summary>
public event EventHandler Cleared;
/// <summary>
/// Initializes a new instance of the ObservableCollection class that is empty.
@ -58,8 +60,8 @@ namespace Nuclex.Support.Collections {
/// <summary>Removes all elements from the Collection</summary>
protected override void ClearItems() {
OnClearing();
base.ClearItems();
OnCleared();
}
/// <summary>
@ -71,7 +73,6 @@ namespace Nuclex.Support.Collections {
/// <param name="item">The zero-based index at which item should be inserted</param>
protected override void InsertItem(int index, ItemType item) {
base.InsertItem(index, item);
OnAdded(item);
}
@ -81,9 +82,7 @@ namespace Nuclex.Support.Collections {
/// <param name="index">The zero-based index of the element to remove</param>
protected override void RemoveItem(int index) {
ItemType item = base[index];
base.RemoveItem(index);
OnRemoved(item);
}
@ -95,9 +94,7 @@ namespace Nuclex.Support.Collections {
/// <param name="item">The zero-based index of the element to replace</param>
protected override void SetItem(int index, ItemType item) {
ItemType oldItem = base[index];
base.SetItem(index, item);
OnRemoved(oldItem);
OnAdded(item);
}
@ -122,6 +119,12 @@ namespace Nuclex.Support.Collections {
Clearing(this, EventArgs.Empty);
}
/// <summary>Fires the 'Cleared' event</summary>
protected virtual void OnCleared() {
if(Cleared != null)
Cleared(this, EventArgs.Empty);
}
}
} // namespace Nuclex.Support.Collections