Show / Hide Table of Contents

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
System.Object
ReadOnlyCollectionBase<T>
Implements
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.ICollection
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

ReadOnlyCollectionBase()

Creates a new ReadOnlyCollectionBase.

Declaration
protected ReadOnlyCollectionBase()

Properties

| Improve this Doc View Source

Count

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 Source

Contains(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 item, false otherwise.

Remarks

You should strongly consider overriding this method to provide a more efficient implementation.

| Improve this Doc View Source

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 converter to each item in this collection in order.

Type Parameters
Name Description
TOutput

The type each item is being converted to.

Exceptions
Type Condition
System.ArgumentNullException

converter is null.

| Improve this Doc View Source

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 array to copy to.

| Improve this Doc View Source

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 predicate.

| Improve this Doc View Source

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 predicate. False if the collection does not contain an item that satisfies predicate.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.Object.ToString()
| Improve this Doc View Source

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 predicate, or if the collection is empty. False if one or more items in the collection do not satisfy predicate.

Explicit Interface Implementations

| Improve this Doc View Source

ICollection<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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 array to copy to.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ICollection.SyncRoot

Indicates the synchronization object for this collection.

Declaration
object ICollection.SyncRoot { get; }
Returns
Type Description
System.Object

Always returns this.

| Improve this Doc View Source

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.

Implements

System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.ICollection
System.Collections.IEnumerable
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX