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:
parent
d5293d8cb9
commit
655ae7ab10
5 changed files with 54 additions and 38 deletions
|
|
@ -32,7 +32,7 @@ namespace Nuclex.Support.Collections {
|
|||
[Serializable]
|
||||
public class ObservableDictionary<KeyType, ValueType> :
|
||||
#if !NO_SERIALIZATION
|
||||
ISerializable,
|
||||
ISerializable,
|
||||
IDeserializationCallback,
|
||||
#endif
|
||||
IDictionary<KeyType, ValueType>,
|
||||
|
|
@ -76,6 +76,8 @@ namespace Nuclex.Support.Collections {
|
|||
public event EventHandler<ItemEventArgs<KeyValuePair<KeyType, ValueType>>> ItemRemoved;
|
||||
/// <summary>Raised when the dictionary is about to be cleared</summary>
|
||||
public event EventHandler Clearing;
|
||||
/// <summary>Raised when the dictionary has been cleared</summary>
|
||||
public event EventHandler Cleared;
|
||||
|
||||
/// <summary>Initializes a new observable dictionary</summary>
|
||||
public ObservableDictionary() : this(new Dictionary<KeyType, ValueType>()) { }
|
||||
|
|
@ -220,6 +222,7 @@ namespace Nuclex.Support.Collections {
|
|||
public void Clear() {
|
||||
OnClearing();
|
||||
this.typedDictionary.Clear();
|
||||
OnCleared();
|
||||
}
|
||||
|
||||
/// <summary>Fires the 'ItemAdded' event</summary>
|
||||
|
|
@ -242,6 +245,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);
|
||||
}
|
||||
|
||||
#region IEnumerable implementation
|
||||
|
||||
/// <summary>Returns a new object enumerator for the Dictionary</summary>
|
||||
|
|
@ -337,6 +346,7 @@ namespace Nuclex.Support.Collections {
|
|||
void ICollection<KeyValuePair<KeyType, ValueType>>.Clear() {
|
||||
OnClearing();
|
||||
this.typedDictionary.Clear();
|
||||
OnCleared();
|
||||
}
|
||||
|
||||
/// <summary>Removes all items from the Dictionary</summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue