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
trueto filter an item.
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- bool:
trueif 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:
trueif 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:
trueifitemis 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 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
| ArgumentException | The number of elements in the source ICollection<T> is greater than the available space from |
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
itemif 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
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()