In This Article

EnumerableView<T> Class

Represents a read-only view on top of an IEnumerable<T> with support for filtering, sorting, and change notifications.

public class EnumerableView<T>
Type Parameters:
T -

The type of items.

Inheritance:
object object

Constructors

EnumerableView(IEnumerable<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

EnumerableView(IEnumerable<T>, IComparer<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection, IComparer<T> sortComparer)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

sortComparer IComparer<T>

The sort comparison logic.

EnumerableView(IEnumerable<T>, Comparison<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection, Comparison<T> sortComparison)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

sortComparison Comparison<T>

The sort comparison logic.

EnumerableView(IEnumerable<T>, Predicate<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection, Predicate<T> filter)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

filter Predicate<T>

The filter logic.

EnumerableView(IEnumerable<T>, Predicate<T>, IComparer<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection, Predicate<T> filter, IComparer<T> sortComparer)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

filter Predicate<T>

The filter logic.

sortComparer IComparer<T>

The sort comparison logic.

EnumerableView(IEnumerable<T>, Predicate<T>, Comparison<T>)

Initializes an instance of the class.

public EnumerableView(IEnumerable<T> collection, Predicate<T> filter, Comparison<T> sortComparison)
Parameter Type Description
collection IEnumerable<T>

The collection to wrap/filter.

filter Predicate<T>

The filter logic.

sortComparison Comparison<T>

The sort comparison logic.

Properties

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int:

The number of elements contained in the ICollection<T>.

FilterPredicate

A filter predicate delegate, which can be used to filter the associated collection.

public Predicate<T>? FilterPredicate { get; set; }

Property Value

Predicate<T>:

The filter logic, which returns true to filter an item.

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool:

true if the ICollection<T> is read-only; otherwise, false.

IsSorting

A value indicating whether this instance is sorting its items.

public bool IsSorting { get; }

Property Value

bool:

true if this instance is sorting its items; otherwise, false.

this[int]

The element at the specified index.

public T this[int index] { get; set; }
Parameter Type Description
index int

The zero-based index of the element to get or set.

Property Value

T

SortComparer

A sort comparer, which can be used to sort the associated collection.

public IComparer<T>? SortComparer { get; set; }

Property Value

IComparer<T>

Remarks

This property takes precedence over the SortComparison property.

SortComparison

A sort comparison delegate, which can be used to sort the associated collection.

public Comparison<T>? SortComparison { get; set; }

Property Value

Comparison<T>

Remarks

The SortComparer property takes precedence over this property.

Methods

Contains(T)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(T item)
Parameter Type Description
item T

The object to locate in the ICollection<T>.

Returns

bool:

true if item is found in the ICollection<T>; otherwise, false.

CopyTo(T[], int)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

public void CopyTo(T[] array, int arrayIndex)
Parameter Type Description
array T[]

The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

Type Condition
ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>:

An enumerator that can be used to iterate through the collection.

IndexOf(T)

Determines the index of a specific item in the IList<T>.

public int IndexOf(T item)
Parameter Type Description
item T

The object to locate in the IList<T>.

Returns

int:

The index of item if found in the list; otherwise, -1.

Reevaluate(T)

Reevaluates the filtering and sorting logic applied to the specified item from the associated collection.

public void Reevaluate(T item)
Parameter Type Description
item T

The item to reevaluate.

ReevaluateAt(int)

Reevaluates the filtering and sorting logic applied to the item at the specified index relative to the associated collection.

public void ReevaluateAt(int index)
Parameter Type Description
index int

The index of the item to reevaluate.

Events

CollectionChanged

Occurs when the collection changes.

public event NotifyCollectionChangedEventHandler? CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

Inherited Members

Extension Methods