From 2d04ad7b49715b576174c92899b58ccd59361761 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Thu, 1 Mar 2012 13:51:04 +0000 Subject: [PATCH] Added ObservableSet and ReadOnlySet wrappers (no unit tests yet) git-svn-id: file:///srv/devel/repo-conversion/nusu@256 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/Collections/ObservableCollection.cs | 4 +- Source/Collections/ObservableDictionary.cs | 15 +- Source/Collections/ObservableList.cs | 4 +- Source/Collections/ObservableSet.cs | 286 +++++++++++++++++++- Source/Collections/ReadOnlyList.cs | 98 +++---- Source/Collections/ReadOnlySet.Test.cs | 50 +++- Source/Collections/ReadOnlySet.cs | 301 +++++++++------------ 7 files changed, 508 insertions(+), 250 deletions(-) diff --git a/Source/Collections/ObservableCollection.cs b/Source/Collections/ObservableCollection.cs index 037129e..7a9155f 100644 --- a/Source/Collections/ObservableCollection.cs +++ b/Source/Collections/ObservableCollection.cs @@ -34,9 +34,9 @@ namespace Nuclex.Support.Collections { ICollection, ICollection, #if !NO_SPECIALIZED_COLLECTIONS - INotifyCollectionChanged, + INotifyCollectionChanged, #endif - IObservableCollection { + IObservableCollection { /// Raised when an item has been added to the collection public event EventHandler> ItemAdded; diff --git a/Source/Collections/ObservableDictionary.cs b/Source/Collections/ObservableDictionary.cs index d5274fe..ca74a84 100644 --- a/Source/Collections/ObservableDictionary.cs +++ b/Source/Collections/ObservableDictionary.cs @@ -36,15 +36,15 @@ namespace Nuclex.Support.Collections { #endif public class ObservableDictionary : #if !NO_SERIALIZATION - ISerializable, + ISerializable, IDeserializationCallback, #endif - IDictionary, + IDictionary, IDictionary, #if !NO_SPECIALIZED_COLLECTIONS - INotifyCollectionChanged, + INotifyCollectionChanged, #endif - IObservableCollection> { + IObservableCollection> { #if !NO_SERIALIZATION #region class SerializedDictionary @@ -300,15 +300,16 @@ namespace Nuclex.Support.Collections { /// Fires the 'Clearing' event protected virtual void OnClearing() { - if(Clearing != null) + if(Clearing != null) { Clearing(this, EventArgs.Empty); + } } /// Fires the 'Cleared' event protected virtual void OnCleared() { - if(Cleared != null) + if(Cleared != null) { Cleared(this, EventArgs.Empty); - + } #if !NO_SPECIALIZED_COLLECTIONS if(CollectionChanged != null) { CollectionChanged(this, Constants.NotifyCollectionResetEventArgs); diff --git a/Source/Collections/ObservableList.cs b/Source/Collections/ObservableList.cs index a04a7c1..0bff02c 100644 --- a/Source/Collections/ObservableList.cs +++ b/Source/Collections/ObservableList.cs @@ -35,9 +35,9 @@ namespace Nuclex.Support.Collections { IList, ICollection, #if !NO_SPECIALIZED_COLLECTIONS - INotifyCollectionChanged, + INotifyCollectionChanged, #endif - IObservableCollection { + IObservableCollection { /// Raised when an item has been added to the collection public event EventHandler> ItemAdded; diff --git a/Source/Collections/ObservableSet.cs b/Source/Collections/ObservableSet.cs index 60eefa4..84d6c77 100644 --- a/Source/Collections/ObservableSet.cs +++ b/Source/Collections/ObservableSet.cs @@ -21,13 +21,291 @@ License along with this library using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Collections; + +#if !NO_SPECIALIZED_COLLECTIONS +using System.Collections.Specialized; +#endif namespace Nuclex.Support.Collections { -#if false - public class ObservableSet { - } + /// Set which fires events when items are removed or added to it + /// Type of items to manage in the set + public class ObservableSet : + ISet, + ICollection, +#if !NO_SPECIALIZED_COLLECTIONS + INotifyCollectionChanged, +#endif + IObservableCollection { + + /// Raised when an item has been added to the collection + public event EventHandler> ItemAdded; + /// Raised when an item is removed from the collection + public event EventHandler> ItemRemoved; + /// Raised when an item is replaced in the collection + public event EventHandler> ItemReplaced { + add { } + remove { } + } + /// Raised when the collection is about to be cleared + /// + /// 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. + /// + public event EventHandler Clearing; + /// Raised when the collection has been cleared + public event EventHandler Cleared; + +#if !NO_SPECIALIZED_COLLECTIONS + /// Called when the collection has changed + public event NotifyCollectionChangedEventHandler CollectionChanged; #endif + /// Initializes a new observable set based on a hashed set + public ObservableSet() : this(new HashSet()) { } + + /// + /// Initializes a new observable set forwarding operations to the specified set + /// + /// Set operations will be forwarded to + public ObservableSet(ISet set) { + this.set = set; + } + + /// Adds an item to the set + /// Item that will be added to the set + /// + /// True if the element was added, false if it was already contained in the set + /// + public bool Add(TItem item) { + return this.set.Add(item); + } + + /// Removes all elements that are contained in the collection + /// Collection whose elements will be removed from this set + public void ExceptWith(IEnumerable other) { + if(other == this) { + Clear(); + return; + } + + foreach(TItem item in other) { + if(this.set.Remove(item)) { + OnRemoved(item); + } + } + } + + /// + /// Only keeps those elements in this set that are contained in the collection + /// + /// Other set this set will be filtered by + public void IntersectWith(IEnumerable other) { + foreach(TItem item in other) { + if(!other.Contains(item)) { + this.set.Remove(item); + OnRemoved(item); + } + } + } + + /// + /// Determines whether the current set is a proper (strict) subset of a collection + /// + /// Collection against which the set will be tested + /// True if the set is a proper subset of the specified collection + public bool IsProperSubsetOf(IEnumerable other) { + return this.set.IsProperSubsetOf(other); + } + + /// + /// Determines whether the current set is a proper (strict) superset of a collection + /// + /// Collection against which the set will be tested + /// True if the set is a proper superset of the specified collection + public bool IsProperSupersetOf(IEnumerable other) { + return this.set.IsProperSupersetOf(other); + } + + /// Determines whether the current set is a subset of a collection + /// Collection against which the set will be tested + /// True if the set is a subset of the specified collection + public bool IsSubsetOf(IEnumerable other) { + return this.set.IsSubsetOf(other); + } + + /// Determines whether the current set is a superset of a collection + /// Collection against which the set will be tested + /// True if the set is a superset of the specified collection + public bool IsSupersetOf(IEnumerable other) { + return this.set.IsSupersetOf(other); + } + + /// + /// Determines if the set shares at least one common element with the collection + /// + /// Collection the set will be tested against + /// + /// True if the set shares at least one common element with the collection + /// + public bool Overlaps(IEnumerable other) { + return this.set.Overlaps(other); + } + + /// + /// Determines whether the set contains the same elements as the specified collection + /// + /// Collection the set will be tested against + /// True if the set contains the same elements as the collection + public bool SetEquals(IEnumerable other) { + return this.set.SetEquals(other); + } + + /// + /// Modifies the current set so that it contains only elements that are present either + /// in the current set or in the specified collection, but not both + /// + /// Collection the set will be excepted with + public void SymmetricExceptWith(IEnumerable other) { + foreach(TItem item in other) { + if(this.set.Remove(item)) { + OnRemoved(item); + } else { + this.Add(item); + OnAdded(item); + } + } + } + + /// + /// Modifies the current set so that it contains all elements that are present in both + /// the current set and in the specified collection + /// + /// Collection an union will be built with + public void UnionWith(IEnumerable other) { + foreach(TItem item in other) { + if(this.set.Add(item)) { + OnAdded(item); + } + } + } + + /// Removes all items from the set + public void Clear() { + OnClearing(); + this.set.Clear(); + OnCleared(); + } + + /// Determines whether the set contains the specified item + /// Item the set will be tested for + /// True if the set contains the specified item + public bool Contains(TItem item) { + return this.set.Contains(item); + } + + /// Copies the contents of the set into an array + /// Array the set's contents will be copied to + /// + /// Index in the array the first copied element will be written to + /// + public void CopyTo(TItem[] array, int arrayIndex) { + this.set.CopyTo(array, arrayIndex); + } + + /// Counts the number of items contained in the set + public int Count { + get { return this.set.Count; } + } + + /// Determines whether the set is readonly + public bool IsReadOnly { + get { return this.set.IsReadOnly; } + } + + /// Removes an item from the set + /// Item that will be removed from the set + /// + /// True if the item was contained in the set and is now removed + /// + public bool Remove(TItem item) { + return this.set.Remove(item); + } + + /// Creates an enumerator for the set's contents + /// A new enumerator for the sets contents + public IEnumerator GetEnumerator() { + return this.set.GetEnumerator(); + } + + /// Fires the 'ItemAdded' event + /// Item that has been added to the collection + protected virtual void OnAdded(TItem item) { + if(ItemAdded != null) { + ItemAdded(this, new ItemEventArgs(item)); + } +#if !NO_SPECIALIZED_COLLECTIONS + if(CollectionChanged != null) { + CollectionChanged( + this, + new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item) + ); + } +#endif + } + + /// Fires the 'ItemRemoved' event + /// Item that has been removed from the collection + protected virtual void OnRemoved(TItem item) { + if(ItemRemoved != null) { + ItemRemoved(this, new ItemEventArgs(item)); + } +#if !NO_SPECIALIZED_COLLECTIONS + if(CollectionChanged != null) { + CollectionChanged( + this, + new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item) + ); + } +#endif + } + + /// Fires the 'Clearing' event + protected virtual void OnClearing() { + if(Clearing != null) { + Clearing(this, EventArgs.Empty); + } + } + + /// Fires the 'Cleared' event + protected virtual void OnCleared() { + if(Cleared != null) { + Cleared(this, EventArgs.Empty); + } +#if !NO_SPECIALIZED_COLLECTIONS + if(CollectionChanged != null) { + CollectionChanged(this, Constants.NotifyCollectionResetEventArgs); + } +#endif + } + + /// Adds an item to the set + /// Item that will be added to the set + void ICollection.Add(TItem item) { + this.set.Add(item); + } + + /// Creates an enumerator for the set's contents + /// A new enumerator for the sets contents + IEnumerator IEnumerable.GetEnumerator() { + return this.set.GetEnumerator(); + } + + /// The set being wrapped + private ISet set; + + } + } // namespace Nuclex.Support.Collections diff --git a/Source/Collections/ReadOnlyList.cs b/Source/Collections/ReadOnlyList.cs index c39f345..d58a134 100644 --- a/Source/Collections/ReadOnlyList.cs +++ b/Source/Collections/ReadOnlyList.cs @@ -24,8 +24,8 @@ using System.Collections.Generic; namespace Nuclex.Support.Collections { - /// Wraps a List and prevents users from modifying it - /// Type of items to manage in the List + /// Wraps a list and prevents users from modifying it + /// Type of items to manage in the set public class ReadOnlyList : IList, IList { /// Initializes a new read-only List wrapper @@ -64,30 +64,30 @@ namespace Nuclex.Support.Collections { this.typedList.CopyTo(array, arrayIndex); } - /// The number of items current contained in the List + /// The number of items current contained in the list public int Count { get { return this.typedList.Count; } } - /// Whether the List is write-protected + /// Whether the list is write-protected public bool IsReadOnly { get { return true; } } - /// Returns a new enumerator over the contents of the List - /// The new List contents enumerator + /// Returns a new enumerator over the contents of the list + /// The new list content enumerator public IEnumerator GetEnumerator() { return this.typedList.GetEnumerator(); } #region IList<> implementation - /// Inserts an item into the List + /// Inserts an item into the list /// Zero-based index before which the item will be inserted - /// Item that will be inserted into the List + /// Item that will be inserted into the list void IList.Insert(int index, TItem item) { throw new NotSupportedException( - "Inserting items is not supported by the read-only List" + "Inserting items is not supported by the read-only list" ); } @@ -95,17 +95,17 @@ namespace Nuclex.Support.Collections { /// Zero-based index of the item that will be removed void IList.RemoveAt(int index) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Removing items is not supported by the read-only list" ); } - /// Accesses the List item with the specified index - /// Zero-based index of the List item that will be accessed + /// Accesses the list item with the specified index + /// Zero-based index of the list item that will be accessed TItem IList.this[int index] { get { return this.typedList[index]; } set { throw new NotSupportedException( - "Assigning items is not supported by the read-only List" + "Assigning items is not supported by the read-only list" ); } } @@ -114,27 +114,27 @@ namespace Nuclex.Support.Collections { #region ICollection<> implementation - /// Adds an item to the end of the List - /// Item that will be added to the List + /// Adds an item to the end of the list + /// Item that will be added to the list void ICollection.Add(TItem item) { throw new NotSupportedException( - "Adding items is not supported by the read-only List" + "Adding items is not supported by the read-only list" ); } /// Removes all items from the List void ICollection.Clear() { throw new NotSupportedException( - "Clearing is not supported by the read-only List" + "Clearing is not supported by the read-only list" ); } - /// Removes the specified item from the List - /// Item that will be removed from the List - /// True of the specified item was found in the List and removed + /// Removes the specified item from the list + /// Item that will be removed from the list + /// True of the specified item was found in the list and removed bool ICollection.Remove(TItem item) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Removing items is not supported by the read-only list" ); } @@ -142,8 +142,8 @@ namespace Nuclex.Support.Collections { #region IEnumerable implementation - /// Returns a new enumerator over the contents of the List - /// The new List contents enumerator + /// Returns a new enumerator over the contents of the list + /// The new list content enumerator IEnumerator IEnumerable.GetEnumerator() { return this.objectList.GetEnumerator(); } @@ -152,55 +152,55 @@ namespace Nuclex.Support.Collections { #region IList implementation - /// Removes all items from the List + /// Removes all items from the list void IList.Clear() { throw new NotSupportedException( - "Clearing is not supported by the read-only List" + "Clearing is not supported by the read-only list" ); } - /// Adds an item to the end of the List - /// Item that will be added to the List + /// Adds an item to the end of the list + /// Item that will be added to the list int IList.Add(object value) { throw new NotSupportedException( - "Adding items is not supported by the read-only List" + "Adding items is not supported by the read-only list" ); } /// Determines whether the List contains the specified item /// Item that will be checked for - /// True if the specified item is contained in the List + /// True if the specified item is contained in the list bool IList.Contains(object value) { return this.objectList.Contains(value); } - /// Retrieves the index of an item within the List + /// Retrieves the index of an item within the list /// Item whose index will be returned - /// The zero-based index of the specified item in the List + /// The zero-based index of the specified item in the list int IList.IndexOf(object value) { return this.objectList.IndexOf(value); } - /// Inserts an item into the List + /// Inserts an item into the list /// Zero-based index before which the item will be inserted - /// Item that will be inserted into the List + /// Item that will be inserted into the list void IList.Insert(int index, object value) { throw new NotSupportedException( - "Inserting items is not supported by the read-only List" + "Inserting items is not supported by the read-only list" ); } - /// Whether the size of the List is fixed + /// Whether the size of the list is fixed bool IList.IsFixedSize { get { return this.objectList.IsFixedSize; } } - /// Removes the specified item from the List - /// Item that will be removed from the List - /// True of the specified item was found in the List and removed + /// Removes the specified item from the list + /// Item that will be removed from the list + /// True of the specified item was found in the list and removed void IList.Remove(object value) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Removing items is not supported by the read-only list" ); } @@ -208,17 +208,17 @@ namespace Nuclex.Support.Collections { /// Zero-based index of the item that will be removed void IList.RemoveAt(int index) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Removing items is not supported by the read-only list" ); } - /// Accesses the List item with the specified index - /// Zero-based index of the List item that will be accessed + /// Accesses the list item with the specified index + /// Zero-based index of the list item that will be accessed object IList.this[int index] { get { return this.objectList[index]; } set { throw new NotSupportedException( - "Assigning items is not supported by the read-only List" + "Assigning items is not supported by the read-only list" ); } } @@ -227,8 +227,8 @@ namespace Nuclex.Support.Collections { #region ICollection implementation - /// Copies the contents of the List into an array - /// Array the List will be copied into + /// Copies the contents of the list into an array + /// Array the list will be copied into /// /// Starting index at which to begin filling the destination array /// @@ -236,21 +236,21 @@ namespace Nuclex.Support.Collections { this.objectList.CopyTo(array, index); } - /// Whether the List is synchronized for multi-threaded usage + /// Whether the list is synchronized for multi-threaded usage bool ICollection.IsSynchronized { get { return this.objectList.IsSynchronized; } } - /// Synchronization root on which the List locks + /// Synchronization root on which the list locks object ICollection.SyncRoot { get { return this.objectList.SyncRoot; } } #endregion - /// The wrapped List under its type-safe interface + /// The wrapped list under its type-safe interface private IList typedList; - /// The wrapped List under its object interface + /// The wrapped list under its object interface private IList objectList; } diff --git a/Source/Collections/ReadOnlySet.Test.cs b/Source/Collections/ReadOnlySet.Test.cs index a6bf504..c10ad72 100644 --- a/Source/Collections/ReadOnlySet.Test.cs +++ b/Source/Collections/ReadOnlySet.Test.cs @@ -1,9 +1,43 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2012 Nuclex Development Labs -namespace Nuclex.Support.Source.Collections { - class ReadOnlySet { - } -} +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 + +#if UNITTEST + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + +using NUnit.Framework; +using NMock; + +namespace Nuclex.Support.Collections { + +#if false + /// Unit Test for the read-only set wrapper + [TestFixture] + internal class ReadOnlySetTest { + } +#endif + +} // namespace Nuclex.Support.Collections + +#endif // UNITTEST \ No newline at end of file diff --git a/Source/Collections/ReadOnlySet.cs b/Source/Collections/ReadOnlySet.cs index 2b18b4b..9ef771c 100644 --- a/Source/Collections/ReadOnlySet.cs +++ b/Source/Collections/ReadOnlySet.cs @@ -21,247 +21,192 @@ License along with this library using System; using System.Collections; using System.Collections.Generic; -using System.Runtime.Serialization; namespace Nuclex.Support.Collections { -#if false - /// Wraps a List and prevents users from modifying it - /// Type of items to manage in the List -#if !NO_SERIALIZATION - [Serializable] -#endif - public class ReadOnlySet : -#if !NO_SERIALIZATION - ISerializable, - IDeserializationCallback, -#endif - ISet, - ICollection { + /// Wraps a set and prevents it from being modified + /// Type of items to manage in the set + public class ReadOnlySet : ISet, ICollection { - /// Initializes a new read-only List wrapper - /// List that will be wrapped - public ReadOnlySet(ISet list) { - this.typedList = list; + /// + /// Initializes a new observable set forwarding operations to the specified set + /// + /// Set operations will be forwarded to + public ReadOnlySet(ISet set) { + this.set = set; } - /// Retrieves the index of an item within the List - /// Item whose index will be returned - /// The zero-based index of the specified item in the List - public int IndexOf(TItem item) { - return this.typedList.IndexOf(item); + /// + /// Determines whether the current set is a proper (strict) subset of a collection + /// + /// Collection against which the set will be tested + /// True if the set is a proper subset of the specified collection + public bool IsProperSubsetOf(IEnumerable other) { + return this.set.IsProperSubsetOf(other); } - /// Accesses the List item with the specified index - /// Zero-based index of the List item that will be accessed - public TItem this[int index] { - get { return this.typedList[index]; } + /// + /// Determines whether the current set is a proper (strict) superset of a collection + /// + /// Collection against which the set will be tested + /// True if the set is a proper superset of the specified collection + public bool IsProperSupersetOf(IEnumerable other) { + return this.set.IsProperSupersetOf(other); } - /// Determines whether the List contains the specified item - /// Item that will be checked for - /// True if the specified item is contained in the List + /// Determines whether the current set is a subset of a collection + /// Collection against which the set will be tested + /// True if the set is a subset of the specified collection + public bool IsSubsetOf(IEnumerable other) { + return this.set.IsSubsetOf(other); + } + + /// Determines whether the current set is a superset of a collection + /// Collection against which the set will be tested + /// True if the set is a superset of the specified collection + public bool IsSupersetOf(IEnumerable other) { + return this.set.IsSupersetOf(other); + } + + /// + /// Determines if the set shares at least one common element with the collection + /// + /// Collection the set will be tested against + /// + /// True if the set shares at least one common element with the collection + /// + public bool Overlaps(IEnumerable other) { + return this.set.Overlaps(other); + } + + /// + /// Determines whether the set contains the same elements as the specified collection + /// + /// Collection the set will be tested against + /// True if the set contains the same elements as the collection + public bool SetEquals(IEnumerable other) { + return this.set.SetEquals(other); + } + + /// Determines whether the set contains the specified item + /// Item the set will be tested for + /// True if the set contains the specified item public bool Contains(TItem item) { - return this.typedList.Contains(item); + return this.set.Contains(item); } - /// Copies the contents of the List into an array - /// Array the List will be copied into + /// Copies the contents of the set into an array + /// Array the set's contents will be copied to /// - /// Starting index at which to begin filling the destination array + /// Index in the array the first copied element will be written to /// public void CopyTo(TItem[] array, int arrayIndex) { - this.typedList.CopyTo(array, arrayIndex); + this.set.CopyTo(array, arrayIndex); } - /// The number of items current contained in the List + /// Counts the number of items contained in the set public int Count { - get { return this.typedList.Count; } + get { return this.set.Count; } } - /// Whether the List is write-protected + /// Determines whether the set is readonly public bool IsReadOnly { get { return true; } } - /// Returns a new enumerator over the contents of the List - /// The new List contents enumerator + + /// Creates an enumerator for the set's contents + /// A new enumerator for the sets contents public IEnumerator GetEnumerator() { - return this.typedList.GetEnumerator(); + return this.set.GetEnumerator(); } - #region IList<> implementation + /// Creates an enumerator for the set's contents + /// A new enumerator for the sets contents + IEnumerator IEnumerable.GetEnumerator() { + return this.set.GetEnumerator(); + } - /// Inserts an item into the List - /// Zero-based index before which the item will be inserted - /// Item that will be inserted into the List - void IList.Insert(int index, TItem item) { + /// + /// Modifies the current set so that it contains only elements that are present either + /// in the current set or in the specified collection, but not both + /// + /// Collection the set will be excepted with + void ISet.SymmetricExceptWith(IEnumerable other) { throw new NotSupportedException( - "Inserting items is not supported by the read-only List" + "Excepting is not supported by the read-only set" ); } - /// Removes an item from the list - /// Zero-based index of the item that will be removed - void IList.RemoveAt(int index) { + /// + /// Modifies the current set so that it contains all elements that are present in both + /// the current set and in the specified collection + /// + /// Collection an union will be built with + void ISet.UnionWith(IEnumerable other) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Unioning is not supported by the read-only set" ); } - /// Accesses the List item with the specified index - /// Zero-based index of the List item that will be accessed - TItem IList.this[int index] { - get { return this.typedList[index]; } - set { - throw new NotSupportedException( - "Assigning items is not supported by the read-only List" - ); - } - } - - #endregion - - #region ICollection<> implementation - - /// Adds an item to the end of the List - /// Item that will be added to the List - void ICollection.Add(TItem item) { + /// Removes all items from the set + public void Clear() { throw new NotSupportedException( - "Adding items is not supported by the read-only List" + "Clearing is not supported by the read-only set" ); } - /// Removes all items from the List - void ICollection.Clear() { - throw new NotSupportedException( - "Clearing is not supported by the read-only List" - ); - } - - /// Removes the specified item from the List - /// Item that will be removed from the List - /// True of the specified item was found in the List and removed + /// Removes an item from the set + /// Item that will be removed from the set + /// + /// True if the item was contained in the set and is now removed + /// bool ICollection.Remove(TItem item) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Removing items is not supported by the read-only set" ); } - #endregion - - #region IEnumerable implementation - - /// Returns a new enumerator over the contents of the List - /// The new List contents enumerator - IEnumerator IEnumerable.GetEnumerator() { - return this.objectList.GetEnumerator(); - } - - #endregion - - #region IList implementation - - /// Removes all items from the List - void IList.Clear() { + /// Adds an item to the set + /// Item that will be added to the set + /// + /// True if the element was added, false if it was already contained in the set + /// + bool ISet.Add(TItem item) { throw new NotSupportedException( - "Clearing is not supported by the read-only List" + "Adding items is not supported by the read-only set" ); } - /// Adds an item to the end of the List - /// Item that will be added to the List - int IList.Add(object value) { + /// Removes all elements that are contained in the collection + /// Collection whose elements will be removed from this set + void ISet.ExceptWith(IEnumerable other) { throw new NotSupportedException( - "Adding items is not supported by the read-only List" + "Excepting items is not supported by the read-only set" ); } - /// Determines whether the List contains the specified item - /// Item that will be checked for - /// True if the specified item is contained in the List - bool IList.Contains(object value) { - return this.objectList.Contains(value); - } - - /// Retrieves the index of an item within the List - /// Item whose index will be returned - /// The zero-based index of the specified item in the List - int IList.IndexOf(object value) { - return this.objectList.IndexOf(value); - } - - /// Inserts an item into the List - /// Zero-based index before which the item will be inserted - /// Item that will be inserted into the List - void IList.Insert(int index, object value) { + /// + /// Only keeps those elements in this set that are contained in the collection + /// + /// Other set this set will be filtered by + void ISet.IntersectWith(IEnumerable other) { throw new NotSupportedException( - "Inserting items is not supported by the read-only List" + "Intersecting items is not supported by the read-only set" ); } - /// Whether the size of the List is fixed - bool IList.IsFixedSize { - get { return this.objectList.IsFixedSize; } - } - - /// Removes the specified item from the List - /// Item that will be removed from the List - /// True of the specified item was found in the List and removed - void IList.Remove(object value) { + /// Adds an item to the set + /// Item that will be added to the set + void ICollection.Add(TItem item) { throw new NotSupportedException( - "Removing items is not supported by the read-only List" + "Adding is not supported by the read-only set" ); } - /// Removes an item from the list - /// Zero-based index of the item that will be removed - void IList.RemoveAt(int index) { - throw new NotSupportedException( - "Removing items is not supported by the read-only List" - ); - } - - /// Accesses the List item with the specified index - /// Zero-based index of the List item that will be accessed - object IList.this[int index] { - get { return this.objectList[index]; } - set { - throw new NotSupportedException( - "Assigning items is not supported by the read-only List" - ); - } - } - - #endregion - - #region ICollection implementation - - /// Copies the contents of the List into an array - /// Array the List will be copied into - /// - /// Starting index at which to begin filling the destination array - /// - void ICollection.CopyTo(Array array, int index) { - this.objectList.CopyTo(array, index); - } - - /// Whether the List is synchronized for multi-threaded usage - bool ICollection.IsSynchronized { - get { return this.objectList.IsSynchronized; } - } - - /// Synchronization root on which the List locks - object ICollection.SyncRoot { - get { return this.objectList.SyncRoot; } - } - - #endregion - - /// The wrapped List under its type-safe interface - private ISet typedList; + /// The set being wrapped + private ISet set; } -#endif } // namespace Nuclex.Support.Collections