Added new interface IObservableCollection which can be used to find out whether a collection can be observed, even if it is only published by its generic .NET interface

git-svn-id: file:///srv/devel/repo-conversion/nusu@123 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-03-19 19:34:11 +00:00
parent 743fc9cc09
commit 889a47db6d
5 changed files with 53 additions and 2 deletions

View File

@ -69,6 +69,7 @@
<Compile Include="Source\AssertHelper.Test.cs"> <Compile Include="Source\AssertHelper.Test.cs">
<DependentUpon>AssertHelper.cs</DependentUpon> <DependentUpon>AssertHelper.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\Collections\IObservableCollection.cs" />
<Compile Include="Source\Collections\ItemEventArgs.cs" /> <Compile Include="Source\Collections\ItemEventArgs.cs" />
<Compile Include="Source\Collections\ItemEventArgs.Test.cs"> <Compile Include="Source\Collections\ItemEventArgs.Test.cs">
<DependentUpon>ItemEventArgs.cs</DependentUpon> <DependentUpon>ItemEventArgs.cs</DependentUpon>

View File

@ -51,6 +51,7 @@
<Compile Include="Source\AssertHelper.Test.cs"> <Compile Include="Source\AssertHelper.Test.cs">
<DependentUpon>AssertHelper.cs</DependentUpon> <DependentUpon>AssertHelper.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\Collections\IObservableCollection.cs" />
<Compile Include="Source\Collections\ItemEventArgs.cs" /> <Compile Include="Source\Collections\ItemEventArgs.cs" />
<Compile Include="Source\Collections\ItemEventArgs.Test.cs"> <Compile Include="Source\Collections\ItemEventArgs.Test.cs">
<DependentUpon>ItemEventArgs.cs</DependentUpon> <DependentUpon>ItemEventArgs.cs</DependentUpon>

View File

@ -0,0 +1,47 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 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 {
/// <summary>Interface for collections that can be observed</summary>
/// <typeparam name="ItemType">Type of items managed in the collection</typeparam>
interface IObservableCollection<ItemType> {
/// <summary>Raised when an item has been added to the collection</summary>
event EventHandler<ItemEventArgs<ItemType>> ItemAdded;
/// <summary>Raised when an item is removed from the collection</summary>
event EventHandler<ItemEventArgs<ItemType>> ItemRemoved;
/// <summary>Raised when the collection is about to be cleared</summary>
/// <remarks>
/// This could be covered by calling ItemRemoved for each item currently
/// contained in the collection, but it is often simpler and more efficient
/// to process the clearing of the entire collection as a special operation.
/// </remarks>
event EventHandler Clearing;
}
} // namespace Nuclex.Support.Collections

View File

@ -25,7 +25,8 @@ using System.Collections.ObjectModel;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
/// <summary>Collection which fires events when items are added or removed</summary> /// <summary>Collection which fires events when items are added or removed</summary>
public class ObservableCollection<ItemType> : Collection<ItemType> { public class ObservableCollection<ItemType> :
Collection<ItemType>, IObservableCollection<ItemType> {
/// <summary>Raised when an item has been added to the collection</summary> /// <summary>Raised when an item has been added to the collection</summary>
public event EventHandler<ItemEventArgs<ItemType>> ItemAdded; public event EventHandler<ItemEventArgs<ItemType>> ItemAdded;

View File

@ -36,7 +36,8 @@ namespace Nuclex.Support.Collections {
IDeserializationCallback, IDeserializationCallback,
#endif #endif
IDictionary<KeyType, ValueType>, IDictionary<KeyType, ValueType>,
IDictionary { IDictionary,
IObservableCollection<KeyValuePair<KeyType, ValueType>> {
#if !COMPACTFRAMEWORK #if !COMPACTFRAMEWORK
#region class SerializedDictionary #region class SerializedDictionary