Class ReadOnlyCollectionBase<T>
ReadOnlyCollectionBase is a base class that can be used to more easily implement the generic ICollection<T> and non-generic ICollection interfaces for a read-only collection: a collection that does not allow adding or removing elements.
Inheritance
Implements
Inherited Members
Namespace: Wintellect.PowerCollections
Assembly: CADability.dll
Syntax
[Serializable]
public abstract class ReadOnlyCollectionBase<T> : ICollection<T>, IEnumerable<T>, ICollection, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | The item type of the collection. |
Remarks
To use ReadOnlyCollectionBase as a base class, the derived class must override the Count and GetEnumerator methods.
ICollection<T>.Contains need not be implemented by the derived class, but it should be strongly considered, because the ReadOnlyCollectionBase implementation may not be very efficient.
Constructors
| Improve this Doc View SourceReadOnlyCollectionBase()
Creates a new ReadOnlyCollectionBase.
Declaration
protected ReadOnlyCollectionBase()
Properties
| Improve this Doc View SourceCount
Must be overridden to provide the number of items in the collection.
Declaration
public abstract int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The number of items in the collection. |
Methods
| Improve this Doc View SourceContains(T)
Determines if the collection contains a particular item. This default implementation
iterates all of the items in the collection via GetEnumerator, testing each item
against item using IComparable<T>.Equals or
Object.Equals.
Declaration
public virtual bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to check for in the collection. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the collection contains |
Remarks
You should strongly consider overriding this method to provide a more efficient implementation.
ConvertAll<TOutput>(Converter<T, TOutput>)
Convert this collection of items by applying a delegate to each item in the collection. The resulting enumeration
contains the result of applying converter to each item in this collection, in
order.
Declaration
public virtual IEnumerable<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Converter<T, TOutput> | converter | A delegate to the method to call, passing each item in this collection. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<TOutput> | An IEnumerable<TOutput^gt; that enumerates the resulting collection from applying |
Type Parameters
| Name | Description |
|---|---|
| TOutput | The type each item is being converted to. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
CopyTo(T[], Int32)
Copies all the items in the collection into an array. Implemented by using the enumerator returned from GetEnumerator to get all the items and copy them to the provided array.
Declaration
public virtual void CopyTo(T[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | Array to copy to. |
| System.Int32 | arrayIndex | Starting index in |
CountWhere(Predicate<T>)
Counts the number of items in the collection that satisfy the condition
defined by predicate.
Declaration
public virtual int CountWhere(Predicate<T> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Predicate<T> | predicate | A delegate that defines the condition to check for. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of items in the collection that satisfy |
Exists(Predicate<T>)
Determines if the collection contains any item that satisfies the condition
defined by predicate.
Declaration
public virtual bool Exists(Predicate<T> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Predicate<T> | predicate | A delegate that defines the condition to check for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the collection contains one or more items that satisfy the condition
defined by |
FindAll(Predicate<T>)
Enumerates the items in the collection that satisfy the condition defined
by predicate.
Declaration
public IEnumerable<T> FindAll(Predicate<T> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Predicate<T> | predicate | A delegate that defines the condition to check for. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | An IEnumerable<T> that enumerates the items that satisfy the condition. |
ForEach(Action<T>)
Performs the specified action on each item in this collection.
Declaration
public virtual void ForEach(Action<T> action)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action<T> | action | An Action delegate which is invoked for each item in this collection. |
GetEnumerator()
Must be overridden to enumerate all the members of the collection.
Declaration
public abstract IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T> | A generic IEnumerator<T> that can be used to enumerate all the items in the collection. |
ToArray()
Creates an array of the correct size, and copies all the items in the collection into the array, by calling CopyTo.
Declaration
public virtual T[] ToArray()
Returns
| Type | Description |
|---|---|
| T[] | An array containing all the elements in the collection, in order. |
ToString()
Shows the string representation of the collection. The string representation contains a list of the items in the collection.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | The string representation of the collection. |
Overrides
TrueForAll(Predicate<T>)
Determines if all of the items in the collection satisfy the condition
defined by predicate.
Declaration
public virtual bool TrueForAll(Predicate<T> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Predicate<T> | predicate | A delegate that defines the condition to check for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if all of the items in the collection satisfy the condition
defined by |
Explicit Interface Implementations
| Improve this Doc View SourceICollection<T>.Add(T)
This method throws an NotSupportedException stating the collection is read-only.
Declaration
void ICollection<T>.Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to be added to the collection. |
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Always thrown. |
ICollection<T>.Clear()
This method throws an NotSupportedException stating the collection is read-only.
Declaration
void ICollection<T>.Clear()
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Always thrown. |
ICollection<T>.IsReadOnly
Indicates whether the collection is read-only. Returns the value of readOnly that was provided to the constructor.
Declaration
bool ICollection<T>.IsReadOnly { get; }
Returns
| Type | Description |
|---|---|
| System.Boolean | Always true. |
ICollection<T>.Remove(T)
This method throws an NotSupportedException stating the collection is read-only.
Declaration
bool ICollection<T>.Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to be removed from the collection. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Always thrown. |
ICollection.CopyTo(Array, Int32)
Copies all the items in the collection into an array. Implemented by using the enumerator returned from GetEnumerator to get all the items and copy them to the provided array.
Declaration
void ICollection.CopyTo(Array array, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | Array to copy to. |
| System.Int32 | index | Starting index in |
ICollection.IsSynchronized
Indicates whether the collection is synchronized.
Declaration
bool ICollection.IsSynchronized { get; }
Returns
| Type | Description |
|---|---|
| System.Boolean | Always returns false, indicating that the collection is not synchronized. |
ICollection.SyncRoot
Indicates the synchronization object for this collection.
Declaration
object ICollection.SyncRoot { get; }
Returns
| Type | Description |
|---|---|
| System.Object | Always returns this. |
IEnumerable.GetEnumerator()
Provides an IEnumerator that can be used to iterate all the members of the collection. This implementation uses the IEnumerator<T> that was overridden by the derived classes to enumerate the members of the collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator | An IEnumerator that can be used to iterate the collection. |