Class ListEx
- Namespace
- Dynamic
Data
- Assembly
- DynamicData.dll
Extensions to help with maintenance of a list.
- Inheritance
-
List
Ex
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.
Parameters
source
IList<T>The source.
items
IEnumerable<T>The items.
index
intThe index.
Type Parameters
T
The type of the item.
AddRange<T>(IList<T>, IEnumerable<T>)
Adds the range to the source list.
Parameters
source
IList<T>The source.
items
IEnumerable<T>The items.
Type Parameters
T
The type of the item.
Exceptions
- Argument
Null Exception source or items.
AddRange<T>(IList<T>, IEnumerable<T>, int)
Adds the range to the list. The starting range is at the specified index.
Parameters
source
IList<T>The source.
items
IEnumerable<T>The items.
index
intThe index.
Type Parameters
T
The type of the item.
Add<T>(IList<T>, IEnumerable<T>)
Adds the items to the specified list.
Parameters
source
IList<T>The source.
items
IEnumerable<T>The items.
Type Parameters
T
The type of the item.
Exceptions
- Argument
Null Exception source or items.
BinarySearch<TItem>(IList<TItem>, TItem)
Performs a binary search on the specified collection.
Parameters
list
IList<TItem>The list to be searched.
value
TItemThe 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
TItemThe 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
TSearchThe 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.
Parameters
source
IList<T>The source.
changes
IChangeSet <T>The changes.
Type Parameters
T
The type of the item.
Exceptions
- Argument
Null Exception 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
- Argument
Null Exception 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
- Argument
Null Exception 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
TThe item.
equalityComparer
IEqualityComparer <T>The equality comparer.
Returns
- Optional<Item
With <T>>Index 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.
Parameters
source
IEnumerable<T>The source enumerable.
item
TThe 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
TThe 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.
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.
Parameters
source
IList<T>The source.
items
IEnumerable<T>The items.
Type Parameters
T
The type of the item.
Exceptions
- Argument
Null Exception source or items.
ReplaceOrAdd<T>(IList<T>, T, T)
Replaces the item if found, otherwise the item is added to the list.
Parameters
source
IList<T>The source.
original
TThe original.
replaceWith
TThe value to replace with.
Type Parameters
T
The type of the item.
Replace<T>(IList<T>, T, T)
Replaces the specified item.
Parameters
source
IList<T>The source.
original
TThe original.
replaceWith
TThe value to replace with.
Type Parameters
T
The type of the item.
Exceptions
- Argument
Null Exception 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
TThe item which is to be replaced. If not in the list and argument exception will be thrown.
replaceWith
TThe 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
- Argument
Null Exception source or items.