Table of Contents

Class IListExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides extension methods for the IList<T> interface.

public static class IListExtensions
Inheritance
IListExtensions
Inherited Members

Methods

AddRange(IList, IEnumerable)

Adds a range of items to the given list.

public static void AddRange(this IList list, IEnumerable items)

Parameters

list IList

The IList on which to add the items.

items IEnumerable

The items to add to the list.

AddRangeAsync<T>(IList<T>, IAsyncEnumerable<IEnumerable<T>>)

Adds a range of elements from an IAsyncEnumerable<T> into the IList<T>.

public static Task AddRangeAsync<T>(this IList<T> list, IAsyncEnumerable<IEnumerable<T>> collection)

Parameters

list IList<T>

The IList<T> to which to add the elements.

collection IAsyncEnumerable<IEnumerable<T>>

The IAsyncEnumerable<T> whose elements to add to the provided list.

Returns

Task

A Task representing the operation of adding all the elements.

Type Parameters

T

The type of the elements contained in the IList<T>.

AddRangeAsync<T>(IList<T>, IAsyncEnumerable<T>)

Adds a range of elements from an IAsyncEnumerable<T> into the IList<T>.

public static Task AddRangeAsync<T>(this IList<T> list, IAsyncEnumerable<T> collection)

Parameters

list IList<T>

The IList<T> to which to add the elements.

collection IAsyncEnumerable<T>

The IAsyncEnumerable<T> whose elements to add to the provided list.

Returns

Task

A Task representing the operation of adding all the elements.

Type Parameters

T

The type of the elements contained in the IList<T>.

AtIndexOrDefaultReadOnly<T>(IReadOnlyList<T>, int)

public static T? AtIndexOrDefaultReadOnly<T>(this IReadOnlyList<T> source, int index)

Parameters

source IReadOnlyList<T>
index int

Returns

T

Type Parameters

T

AtIndexOrDefault<T>(IList<T>, int)

public static T? AtIndexOrDefault<T>(this IList<T> source, int index)

Parameters

source IList<T>
index int

Returns

T

Type Parameters

T

ClearSetRange(IList, IEnumerable)

Clears the entire list and sets its contents to the given range.

public static void ClearSetRange(this IList list, IEnumerable items)

Parameters

list IList

The IList to clear and whose items to set.

items IEnumerable

The items to set to the list.

Insert<T>(IList<T>, Index, T)

Inserts an element to the list at the specified index.

public static void Insert<T>(this IList<T> list, Index index, T element)

Parameters

list IList<T>

The list to add an element to.

index Index

The index that the element will be located at after insertion.

element T

The element to insert to the list.

Type Parameters

T

The type of the elements contained in the IList<T>.

Pop<T>(IList<T>)

Pops the last element from the list and returns it.

public static T Pop<T>(this IList<T> list)

Parameters

list IList<T>

The list from which to pop the element.

Returns

T

The popped element.

Type Parameters

T

The type of the elements in the list.

RemoveAtDecrement<T>(IList<T>, ref int)

Removes an element from the list at the specified index and decrements the provided index by reference.

public static void RemoveAtDecrement<T>(this IList<T> list, ref int index)

Parameters

list IList<T>

The list from which to remove the element.

index int

A reference to the index that will be decremented after removing the element from the list.

Type Parameters

T

The type of the elements in the list.

RemoveAt<T>(IList<T>, Index)

Removes an element from the list at the specified index.

public static void RemoveAt<T>(this IList<T> list, Index index)

Parameters

list IList<T>

The list to remove an element from.

index Index

The index of the element in the list to remove.

Type Parameters

T

The type of the elements contained in the IList<T>.

RemoveLast<T>(IList<T>)

Removes the last element from the provided list.

public static void RemoveLast<T>(this IList<T> list)

Parameters

list IList<T>

The list to remove the last element from.

Type Parameters

T

The type of the elements contained in the IList<T>.

SingleOrDefaultReadOnly<T>(IReadOnlyList<T>)

public static T? SingleOrDefaultReadOnly<T>(this IReadOnlyList<T> source)

Parameters

source IReadOnlyList<T>

Returns

T

Type Parameters

T

SingleOrDefaultSafe<T>(IList<T>)

public static T? SingleOrDefaultSafe<T>(this IList<T> source)

Parameters

source IList<T>

Returns

T

Type Parameters

T

Swap<T>(IList<T>, Index, Index)

Swaps two elements in the IList<T>.

public static IList<T> Swap<T>(this IList<T> list, Index a, Index b)

Parameters

list IList<T>

The IList<T> within which to swap two elements.

a Index

The index of the first element to swap.

b Index

The index of the second element to swap.

Returns

IList<T>

The instance of the IList<T> in which two elements were swapped.

Type Parameters

T

The type of the elements contained in the IList<T>.

Swap<T>(IList<T>, int, int)

Swaps two elements in the IList<T>.

public static IList<T> Swap<T>(this IList<T> list, int a, int b)

Parameters

list IList<T>

The IList<T> within which to swap two elements.

a int

The index of the first element to swap.

b int

The index of the second element to swap.

Returns

IList<T>

The instance of the IList<T> in which two elements were swapped.

Type Parameters

T

The type of the elements contained in the IList<T>.

TryGetAtIndexReadOnly<T>(IReadOnlyList<T>, int, out T?)

public static bool TryGetAtIndexReadOnly<T>(this IReadOnlyList<T> source, int index, out T? value)

Parameters

source IReadOnlyList<T>
index int
value T

Returns

bool

Type Parameters

T

TryGetAtIndex<T>(IList<T>, int, out T?)

public static bool TryGetAtIndex<T>(this IList<T> source, int index, out T? value)

Parameters

source IList<T>
index int
value T

Returns

bool

Type Parameters

T