Class CollectionUtils
Extensions for standard collections
Inheritance
System.Object
CollectionUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Azos
Assembly: Azos.dll
Syntax
public static class CollectionUtils
Methods
AddRange<TKey, TValue>(IDictionary<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>)
Add all values from range sequence to src IDictionary. Source is actually modified.
Declaration
public static IDictionary<TKey, TValue> AddRange<TKey, TValue>(this IDictionary<TKey, TValue> src, IEnumerable<KeyValuePair<TKey, TValue>> range)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IDictionary<TKey, TValue> |
src |
Source IDictionary (where to add range)
|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
range |
Sequence that should be added to source IDictionary
|
Returns
Type |
Description |
System.Collections.Generic.IDictionary<TKey, TValue> |
Source with added elements from range (to have ability to chain operations)
|
Type Parameters
Name |
Description |
TKey |
Type of key
|
TValue |
Type of value
|
AppendToNew<T>(T[], T[])
Returns a new array that contains source elements with additional elements appended at the end
Declaration
public static T[] AppendToNew<T>(this T[] source, params T[] elements)
Parameters
Type |
Name |
Description |
T[] |
source |
|
T[] |
elements |
|
Returns
Type Parameters
ConcatArray<T>(T, T[])
Returns an array concatenated from the first element and the rest, similar to JS rest spread operator: let x = [first, ...rest];
Declaration
public static T[] ConcatArray<T>(this T first, params T[] theRest)
Parameters
Type |
Name |
Description |
T |
first |
|
T[] |
theRest |
|
Returns
Type Parameters
DistinctBy<TResult, TKey>(IEnumerable<TResult>, Func<TResult, TKey>, IEqualityComparer<TKey>)
Returns sequence of items distinct by the selected key. If key selection functor is null then returns input as-is
Declaration
public static IEnumerable<TResult> DistinctBy<TResult, TKey>(this IEnumerable<TResult> source, Func<TResult, TKey> selector, IEqualityComparer<TKey> distinctEqualityComparer = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TKey> |
selector |
|
System.Collections.Generic.IEqualityComparer<TKey> |
distinctEqualityComparer |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TResult> |
|
Type Parameters
Name |
Description |
TResult |
|
TKey |
|
FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
Declaration
public static TResult FirstMax<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector)
where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
Declaration
public static TResult FirstMax<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector, out TComparand maxComparand)
where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
TComparand |
maxComparand |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
Declaration
public static TResult FirstMin<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector)
where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
Declaration
public static TResult FirstMin<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector, out TComparand minComparand)
where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
TComparand |
minComparand |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstOrAnyOrDefault<TResult>(IEnumerable<TResult>, Func<TResult, Boolean>)
Tries to find the first element that matches the predicate and returns it,
otherwise returns the first element found or default (i.e. null)
Declaration
public static TResult FirstOrAnyOrDefault<TResult>(this IEnumerable<TResult> source, Func<TResult, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, System.Boolean> |
predicate |
|
Returns
Type Parameters
ForEach<T>(IEnumerable<T>, Action<T, Int32>)
Executes an action(item, idx) for each element of sequence
Declaration
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> src, Action<T, int> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
src |
Source sequence
|
System.Action<T, System.Int32> |
action |
Action to invoke
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
Source sequence
|
Type Parameters
Name |
Description |
T |
Sequence item type
|
ForEach<T>(IEnumerable<T>, Action<T>)
Executes an action(item) for each element of sequence
Declaration
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> src, Action<T> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
src |
Source sequence
|
System.Action<T> |
action |
Action to invoke
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
Source sequence
|
Type Parameters
Name |
Description |
T |
Sequence item type
|
SkipLast<T>(IEnumerable<T>)
Takes all elements except for the last element from the given source
Declaration
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
SkipLast<T>(IEnumerable<T>, Int32)
Takes all but the last N elements from the source
Declaration
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int n)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
System.Int32 |
n |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters