Table of Contents

Class IListExtensions

Namespace
SunamoExtensions
Assembly
SunamoExtensions.dll

Extension methods for IList and IEnumerable types

public static class IListExtensions
Inheritance
IListExtensions
Inherited Members

Methods

Count(IEnumerable)

Counts the number of elements in the enumerable

public static int Count(this IEnumerable enumerable)

Parameters

enumerable IEnumerable

Enumerable to count

Returns

int

Number of elements

Count2<T>(IList<T>)

Counts elements in the list (renamed to avoid conflict with LINQ Count)

public static int Count2<T>(this IList<T> list)

Parameters

list IList<T>

List to count

Returns

int

Number of elements

Type Parameters

T

Type of elements in the list

Count3(IList)

Counts elements in non-generic list (renamed to avoid ambiguity)

public static int Count3(this IList list)

Parameters

list IList

List to count

Returns

int

Number of elements

DumpAsString<T>(IList<T>, string, object)

Dumps the list as a string representation

public static string DumpAsString<T>(this IList<T> list, string operation, object args)

Parameters

list IList<T>

List to dump

operation string

Operation name

args object

Additional arguments

Returns

string

String representation

Type Parameters

T

Type of elements in the list

Exceptions

Exception

This method is not implemented

First2(IList)

Returns the first element or null (renamed to avoid conflict with LINQ First)

public static object? First2(this IList list)

Parameters

list IList

List to get first element from

Returns

object

First element or null

FirstOrNull(IEnumerable)

Returns the first element or null if the enumerable is empty

public static object? FirstOrNull(this IEnumerable enumerable)

Parameters

enumerable IEnumerable

Enumerable to get first element from

Returns

object

First element or null

Length2<T>(IList<T>)

Returns the length of the list

public static int Length2<T>(this IList<T> list)

Parameters

list IList<T>

List to get length of

Returns

int

Number of elements

Type Parameters

T

Type of elements in the list

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

Removes element at specified index (creates new list)

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

Parameters

list IList<T>

Source list

index int

Index of element to remove

Returns

IList<T>

New list with element removed

Type Parameters

T

Type of elements in the list

RemoveLast<T>(IList<T>)

Removes the last element from the list

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

Parameters

list IList<T>

List to modify

Returns

List<T>

Modified list

Type Parameters

T

Type of elements in the list

SortAsc<T>(List<T>)

Sorts the list in ascending order

public static void SortAsc<T>(this List<T> list)

Parameters

list List<T>

List to sort

Type Parameters

T

Type of elements in the list

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

Swaps two elements in the list

public static void Swap<T>(this IList<T> list, int firstIndex, int secondIndex)

Parameters

list IList<T>

List to modify

firstIndex int

Index of first element

secondIndex int

Index of second element

Type Parameters

T

Type of elements in the list

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

Takes the last N elements from the list

public static IList<T> TakeLast<T>(this IList<T> source, int count)

Parameters

source IList<T>

Source list

count int

Number of elements to take

Returns

IList<T>

List containing the last N elements

Type Parameters

T

Type of elements in the list

Where2<TSource>(IList<TSource>, Func<TSource, bool>)

Filters elements based on a predicate

public static IList<TSource> Where2<TSource>(this IList<TSource> source, Func<TSource, bool> predicate)

Parameters

source IList<TSource>

Source list

predicate Func<TSource, bool>

Predicate to filter by

Returns

IList<TSource>

Filtered list

Type Parameters

TSource

Type of elements in the list

WhereNonGeneric(IList, Func<object, bool>)

Filters non-generic enumerable based on a predicate

public static List<object> WhereNonGeneric(this IList list, Func<object, bool> predicate)

Parameters

list IList

List to filter

predicate Func<object, bool>

Predicate to filter by

Returns

List<object>

Filtered list of objects