Class GorgonIReadOnlyListExtensions
Extension methods for items that were inexplicably omitted from the IReadOnlyList<T> interface.
Inherited Members
Namespace: Gorgon.Collections
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonIReadOnlyListExtensions
Methods
| Edit this page View SourceContains<T>(IReadOnlyList<T>, T)
Function to determine if an item of type T
exists within the list.
Declaration
public static bool Contains<T>(this IReadOnlyList<T> list, T item)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list to evaluate. |
T | item | The item to find in the list. |
Returns
Type | Description |
---|---|
bool | true if the |
Type Parameters
Name | Description |
---|---|
T |
Remarks
This method scans through a IReadOnlyList<T> to locate the specified item
. If the item is found, then true is returned, and if not, then false
is returned instead.
The search will use a native implementation of the Contains method on the list
concrete type if available. Otherwise, if the type, T
implements
IEquatable<T> then that is used for comparing items the list. If that interface is not available, then IComparable<T> is used, and failing that, the
Equals(object) method is used to determine equality between the items in the list.
For best performance, it is best to use a type that natively Contains in its concrete implementation.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
CopyTo<T>(IReadOnlyList<T>, T[])
Function to copy the contents of this read only list into an array.
Declaration
public static void CopyTo<T>(this IReadOnlyList<T> list, T[] array)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list to evaluate. |
T[] | array | The array that will receive the data. |
Type Parameters
Name | Description |
---|---|
T | The type of data to copy. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentException | Thrown when the |
FirstIndexOf<T>(IReadOnlyList<T>, Predicate<T>)
Function to find the first index of an item using a predicate to filter through the list.
Declaration
public static int FirstIndexOf<T>(this IReadOnlyList<T> list, Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list to evaluate. |
Predicate<T> | predicate | The predicate function used to evaluate the list items. |
Returns
Type | Description |
---|---|
int | The index of the filtered item, or -1 if not found. |
Type Parameters
Name | Description |
---|---|
T | The type of values in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
IndexOf<T>(IReadOnlyList<T>, T)
Function to return the index of an item in a IReadOnlyList<T>.
Declaration
public static int IndexOf<T>(this IReadOnlyList<T> list, T item)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list of items to evaluate. |
T | item | The item to search for. |
Returns
Type | Description |
---|---|
int | The index of the |
Type Parameters
Name | Description |
---|---|
T | The type of object in the collection. |
Remarks
This method scans through a IReadOnlyList<T> to locate the specified item
. If the item is found, the index of that item within the list
is returned. Otherwise, if it is not found, -1
is returned.
The search will use a native implementation of the IndexOf method on the list
concrete type if available. Otherwise, if the type, T
implements
IEquatable<T> then that is used for comparing items the list. If that interface is not available, then IComparable<T> is used, and failing that, the
Equals(object) method is used to determine equality between the items in the list.
For best performance, it is best to use a type that natively IndexOf in its concrete implementation.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
LastIndexOf<T>(IReadOnlyList<T>, Predicate<T>)
Function to find the last index of an item using a predicate to filter through the list.
Declaration
public static int LastIndexOf<T>(this IReadOnlyList<T> list, Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list to evaluate. |
Predicate<T> | predicate | The predicate function used to evaluate the list items. |
Returns
Type | Description |
---|---|
int | The index of the filtered item, or -1 if not found. |
Type Parameters
Name | Description |
---|---|
T | The type of values in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |