Table of Contents

Class ListEx

Namespace
DynamicData
Assembly
DynamicData.dll

Extensions to help with maintenance of a list.

public static class ListEx
Inheritance
ListEx

Methods

AddOrInsertRange<T>(IList<T>, IEnumerable<T>, int)

Adds the range if a negative is specified, otherwise the range is added at the end of the list.

public static void AddOrInsertRange<T>(this IList<T> source, IEnumerable<T> items, int index)

Parameters

source IList<T>

The source.

items IEnumerable<T>

The items.

index int

The index.

Type Parameters

T

The type of the item.

AddRange<T>(IList<T>, IEnumerable<T>)

Adds the range to the source ist.

public static void AddRange<T>(this IList<T> source, IEnumerable<T> items)

Parameters

source IList<T>

The source.

items IEnumerable<T>

The items.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or items.

AddRange<T>(IList<T>, IEnumerable<T>, int)

Adds the range to the list. The starting range is at the specified index.

public static void AddRange<T>(this IList<T> source, IEnumerable<T> items, int index)

Parameters

source IList<T>

The source.

items IEnumerable<T>

The items.

index int

The index.

Type Parameters

T

The type of the item.

Add<T>(IList<T>, IEnumerable<T>)

Adds the items to the specified list.

public static void Add<T>(this IList<T> source, IEnumerable<T> items)

Parameters

source IList<T>

The source.

items IEnumerable<T>

The items.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or items.

BinarySearch<TItem>(IList<TItem>, TItem)

Performs a binary search on the specified collection.

public static int BinarySearch<TItem>(this IList<TItem> list, TItem value)

Parameters

list IList<TItem>

The list to be searched.

value TItem

The value to search for.

Returns

int

The index of the specified value in the specified array, if value is found; otherwise, a negative number.

Type Parameters

TItem

The type of the item.

BinarySearch<TItem>(IList<TItem>, TItem, IComparer<TItem>)

Performs a binary search on the specified collection.

public static int BinarySearch<TItem>(this IList<TItem> list, TItem value, IComparer<TItem> comparer)

Parameters

list IList<TItem>

The list to be searched.

value TItem

The value to search for.

comparer IComparer<TItem>

The comparer that is used to compare the value with the list items.

Returns

int

The index of the specified value in the specified array, if value is found; otherwise, a negative number.

Type Parameters

TItem

The type of the item.

BinarySearch<TItem, TSearch>(IList<TItem>, TSearch, Func<TSearch, TItem, int>)

Performs a binary search on the specified collection.

Thanks to https://stackoverflow.com/questions/967047/how-to-perform-a-binary-search-on-ilistt.

public static int BinarySearch<TItem, TSearch>(this IList<TItem> list, TSearch value, Func<TSearch, TItem, int> comparer)

Parameters

list IList<TItem>

The list to be searched.

value TSearch

The value to search for.

comparer Func<TSearch, TItem, int>

The comparer that is used to compare the value with the list items.

Returns

int

The index of the specified value in the specified array, if value is found; otherwise, a negative number.

Type Parameters

TItem

The type of the item.

TSearch

The type of the searched item.

Clone<T>(IList<T>, IChangeSet<T>)

Clones the list from the specified change set.

public static void Clone<T>(this IList<T> source, IChangeSet<T> changes) where T : notnull

Parameters

source IList<T>

The source.

changes IChangeSet<T>

The changes.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or changes.

Clone<T>(IList<T>, IChangeSet<T>, IEqualityComparer<T>?)

Clones the list from the specified change set.

public static void Clone<T>(this IList<T> source, IChangeSet<T> changes, IEqualityComparer<T>? equalityComparer) where T : notnull

Parameters

source IList<T>

The source.

changes IChangeSet<T>

The changes.

equalityComparer IEqualityComparer<T>

An equality comparer to match items in the changes.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or changes.

Clone<T>(IList<T>, IEnumerable<Change<T>>, IEqualityComparer<T>?)

Clones the list from the specified enumerable of changes.

public static void Clone<T>(this IList<T> source, IEnumerable<Change<T>> changes, IEqualityComparer<T>? equalityComparer) where T : notnull

Parameters

source IList<T>

The source.

changes IEnumerable<Change<T>>

The changes.

equalityComparer IEqualityComparer<T>

An equality comparer to match items in the changes.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or changes.

IndexOfOptional<T>(IEnumerable<T>, T, IEqualityComparer<T>?)

Lookups the item using the specified comparer. If matched, the item's index is also returned.

public static Optional<ItemWithIndex<T>> IndexOfOptional<T>(this IEnumerable<T> source, T item, IEqualityComparer<T>? equalityComparer = null)

Parameters

source IEnumerable<T>

The source.

item T

The item.

equalityComparer IEqualityComparer<T>

The equality comparer.

Returns

Optional<ItemWithIndex<T>>

The index of the item if available.

Type Parameters

T

The type of the item.

IndexOf<T>(IEnumerable<T>, T)

Finds the index of the current item using the specified equality comparer.

public static int IndexOf<T>(this IEnumerable<T> source, T item)

Parameters

source IEnumerable<T>

The source enumerable.

item T

The item to get the index of.

Returns

int

The index.

Type Parameters

T

The type of the item.

IndexOf<T>(IEnumerable<T>, T, IEqualityComparer<T>)

Finds the index of the current item using the specified equality comparer.

public static int IndexOf<T>(this IEnumerable<T> source, T item, IEqualityComparer<T> equalityComparer)

Parameters

source IEnumerable<T>

The source enumerable.

item T

The item to get the index of.

equalityComparer IEqualityComparer<T>

Use to determine object equality.

Returns

int

The index.

Type Parameters

T

The type of the item.

RemoveMany<T>(IList<T>, IEnumerable<T>)

Removes many items from the collection in an optimal way.

public static void RemoveMany<T>(this IList<T> source, IEnumerable<T> itemsToRemove)

Parameters

source IList<T>

The source.

itemsToRemove IEnumerable<T>

The items to remove.

Type Parameters

T

The type of the item.

Remove<T>(IList<T>, IEnumerable<T>)

Removes the items from the specified list.

public static void Remove<T>(this IList<T> source, IEnumerable<T> items)

Parameters

source IList<T>

The source.

items IEnumerable<T>

The items.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or items.

ReplaceOrAdd<T>(IList<T>, T, T)

Replaces the item if found, otherwise the item is added to the list.

public static void ReplaceOrAdd<T>(this IList<T> source, T original, T replaceWith)

Parameters

source IList<T>

The source.

original T

The original.

replaceWith T

The value to replace with.

Type Parameters

T

The type of the item.

Replace<T>(IList<T>, T, T)

Replaces the specified item.

public static void Replace<T>(this IList<T> source, T original, T replaceWith)

Parameters

source IList<T>

The source.

original T

The original.

replaceWith T

The value to replace with.

Type Parameters

T

The type of the item.

Exceptions

ArgumentNullException

source or items.

Replace<T>(IList<T>, T, T, IEqualityComparer<T>)

Replaces the specified item.

public static void Replace<T>(this IList<T> source, T original, T replaceWith, IEqualityComparer<T> comparer)

Parameters

source IList<T>

The source.

original T

The item which is to be replaced. If not in the list and argument exception will be thrown.

replaceWith T

The new item.

comparer IEqualityComparer<T>

The equality comparer to be used to find the original item in the list.

Type Parameters

T

The type of item.

Exceptions

ArgumentNullException

source or items.