Class EnumerableExtensions
Inheritance
System.Object
EnumerableExtensions
Assembly: Eco.Shared.dll
Syntax
public static class EnumerableExtensions : Object
Methods
Any<T>(List<T>, Func<T, Boolean>)
Specialized version for System.Collections.Generic.List<>. No allocations.
Declaration
public static bool Any<T>(this List<T> list, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.List<T> |
list |
|
System.Func<T, System.Boolean> |
predicate |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
AnyNotNull<T>(IEnumerable<T>)
Checks if collection contains at least 1 not null element
Declaration
public static bool AnyNotNull<T>(this IEnumerable<T> objects)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
objects |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
AppendNullSafe<T>(IEnumerable<T>, T)
Declaration
public static IEnumerable<T> AppendNullSafe<T>(this IEnumerable<T> source, T element)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
T |
element |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
AsCollection<T>(IEnumerable<T>)
Represents enumerable as System.Collections.Generic.ICollection<> avoiding copy creation if not necessary.
Declaration
public static ICollection<T> AsCollection<T>(this IEnumerable<T> this)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
this |
|
Returns
Type |
Description |
System.Collections.Generic.ICollection<T> |
|
Type Parameters
AsList<T>(IEnumerable<T>)
Declaration
public static IList<T> AsList<T>(this IEnumerable<T> this)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
this |
|
Returns
Type |
Description |
System.Collections.Generic.IList<T> |
|
Type Parameters
AsReadOnlyList<T>(IEnumerable<T>)
Represents enumerable as System.Collections.Generic.IReadOnlyList<> avoiding copy creation if not necessary.
Declaration
public static IReadOnlyList<T> AsReadOnlyList<T>(this IEnumerable<T> this)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
this |
|
Returns
Type |
Description |
System.Collections.Generic.IReadOnlyList<T> |
|
Type Parameters
AverageOrDefault(IEnumerable<Single>, Single)
Declaration
public static float AverageOrDefault(this IEnumerable<float> source, float defaultValue = 0F)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<System.Single> |
source |
|
System.Single |
defaultValue |
|
Returns
Type |
Description |
System.Single |
|
Cast(IEnumerable, Type)
Casts enumerable
to System.Collections.Generic.IEnumerable<>. Is useful when you need to cast to specific runtime type, but can't use generic type arguments.
Declaration
public static IEnumerable Cast(this IEnumerable enumerable, Type type)
Parameters
Type |
Name |
Description |
System.Collections.IEnumerable |
enumerable |
|
System.Type |
type |
|
Returns
Type |
Description |
System.Collections.IEnumerable |
|
CompareNullSafe<T>(IEnumerable<T>, IEnumerable<T>)
Declaration
public static bool CompareNullSafe<T>(this IEnumerable<T> left, IEnumerable<T> right)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
left |
|
System.Collections.Generic.IEnumerable<T> |
right |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
ConcatNullSafe<T>(IEnumerable<T>, IEnumerable<T>)
Concat two enumerable if possible (both not null). If any enum is null then it will be omitted from concatenation and only non-null enumerable elements will be returned.
If both null then it will return empty enumerable.
Declaration
public static IEnumerable<T> ConcatNullSafe<T>(this IEnumerable<T> left, IEnumerable<T> right)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
left |
|
System.Collections.Generic.IEnumerable<T> |
right |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
ConcatNullSafe<T>(IEnumerable<T>, IEnumerable<T>, Boolean)
Declaration
public static IEnumerable<T> ConcatNullSafe<T>(this IEnumerable<T> left, IEnumerable<T> right, bool nullAllowed)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
left |
|
System.Collections.Generic.IEnumerable<T> |
right |
|
System.Boolean |
nullAllowed |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
ContainsAll<T>(IEnumerable<T>, IEnumerable<T>)
Declaration
public static bool ContainsAll<T>(this IEnumerable<T> objects, IEnumerable<T> mustContain)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
objects |
|
System.Collections.Generic.IEnumerable<T> |
mustContain |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
CountFromLast<T>(IEnumerable<T>, Int32)
Declaration
public static T CountFromLast<T>(this IEnumerable<T> list, int i)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Int32 |
i |
|
Returns
Type Parameters
DependencySorted<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
Declaration
public static List<T> DependencySorted<T>(this IEnumerable<T> items, Func<T, IEnumerable<T>> dependencyFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
|
System.Func<T, System.Collections.Generic.IEnumerable<T>> |
dependencyFunc |
|
Returns
Type |
Description |
System.Collections.Generic.List<T> |
|
Type Parameters
Duplicates<T, TR>(IEnumerable<T>, Func<T, TR>)
Declaration
public static IEnumerable<T> Duplicates<T, TR>(this IEnumerable<T> list, Func<T, TR> keySelector)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Func<T, TR> |
keySelector |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
FallbackIfEmpty<T>(IEnumerable<T>, Func<IEnumerable<T>>)
Fallback to another enumerable provided by fallbackProvider
if enumerable
is empty.
Declaration
public static IEnumerable<T> FallbackIfEmpty<T>(this IEnumerable<T> enumerable, Func<IEnumerable<T>> fallbackProvider)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Func<System.Collections.Generic.IEnumerable<T>> |
fallbackProvider |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
FirstIndex<T>(IEnumerable<T>, Predicate<T>)
Declaration
public static int FirstIndex<T>(this IEnumerable<T> list, Predicate<T> test)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Predicate<T> |
test |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
FirstOfTypeOrDefault<T>(IList)
Returns first value in list of type T
or default value. No allocations.
Declaration
public static T FirstOfTypeOrDefault<T>(this IList list)
Parameters
Type |
Name |
Description |
System.Collections.IList |
list |
|
Returns
Type Parameters
Flatten<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
Declaration
public static IEnumerable<T> Flatten<T>(this IEnumerable<T> list, Func<T, IEnumerable<T>> generateChildren)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Func<T, System.Collections.Generic.IEnumerable<T>> |
generateChildren |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
ForEach<T>(IEnumerable<T>, Action<T>)
Declaration
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Action<T> |
action |
|
Type Parameters
ForEach<T, TContext>(IEnumerable<T>, TContext, Action<T, TContext>)
Calls action for each element with context preferring no-alloc enumerator version (avoiding boxing).
Declaration
public static void ForEach<T, TContext>(this IEnumerable<T> enumerable, TContext context, Action<T, TContext> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
enumerable.
|
TContext |
context |
context.
|
System.Action<T, TContext> |
action |
action.
|
Type Parameters
Name |
Description |
T |
item type.
|
TContext |
context type.
|
ForEach<T, TContext>(List<T>, TContext, Action<T, TContext>)
Calls action for each element with the context for a list.
Declaration
public static void ForEach<T, TContext>(this List<T> list, TContext context, Action<T, TContext> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.List<T> |
list |
list.
|
TContext |
context |
context.
|
System.Action<T, TContext> |
action |
action.
|
Type Parameters
Name |
Description |
T |
item type.
|
TContext |
context type.
|
ForEach<TKey, TValue, TContext>(Dictionary<TKey, TValue>, TContext, Action<KeyValuePair<TKey, TValue>, TContext>)
Calls action for each entry with the context for a dictionary.
Declaration
public static void ForEach<TKey, TValue, TContext>(this Dictionary<TKey, TValue> dict, TContext context, Action<KeyValuePair<TKey, TValue>, TContext> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.Dictionary<TKey, TValue> |
dict |
dictionary.
|
TContext |
context |
context.
|
System.Action<System.Collections.Generic.KeyValuePair<TKey, TValue>, TContext> |
action |
action.
|
Type Parameters
Name |
Description |
TKey |
key type.
|
TValue |
value type.
|
TContext |
context type.
|
ForEach<TKey, TValue, TContext>(IDictionary<TKey, TValue>, TContext, Action<KeyValuePair<TKey, TValue>, TContext>)
Calls action for each entry with the context for a dictionary preferring no-alloc enumerator version (avoiding boxing).
Declaration
public static void ForEach<TKey, TValue, TContext>(this IDictionary<TKey, TValue> dict, TContext context, Action<KeyValuePair<TKey, TValue>, TContext> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IDictionary<TKey, TValue> |
dict |
dictionary.
|
TContext |
context |
context.
|
System.Action<System.Collections.Generic.KeyValuePair<TKey, TValue>, TContext> |
action |
action.
|
Type Parameters
Name |
Description |
TKey |
key type.
|
TValue |
value type.
|
TContext |
context type.
|
ForEachIndex<T>(IEnumerable<T>, Action<T, Int32>)
Declaration
public static void ForEachIndex<T>(this IEnumerable<T> enumerable, Action<T, int> handler)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Action<T, System.Int32> |
handler |
|
Type Parameters
ForEachReverse<T>(IList<T>, Action<T>)
Declaration
public static void ForEachReverse<T>(this IList<T> list, Action<T> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<T> |
list |
|
System.Action<T> |
action |
|
Type Parameters
ForEachUntil<T>(IEnumerable<T>, Func<T, Boolean>)
Declaration
public static bool ForEachUntil<T>(this IEnumerable<T> list, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Func<T, System.Boolean> |
predicate |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
GetDistinctBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)
Declaration
public static IEnumerable<TSource> GetDistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<TSource, TKey> |
keySelector |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TSource> |
|
Type Parameters
Name |
Description |
TSource |
|
TKey |
|
IsOrdered<TKey, TValue>(IEnumerable<TKey>, Func<TKey, TValue>)
Declaration
public static bool IsOrdered<TKey, TValue>(this IEnumerable<TKey> list, Func<TKey, TValue> predicate)
where TValue : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TKey> |
list |
|
System.Func<TKey, TValue> |
predicate |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
MaxObj<T>(IEnumerable<T>, Func<T, Double>)
Declaration
public static T MaxObj<T>(this IEnumerable<T> enumeration, Func<T, double> distanceFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Double> |
distanceFunc |
|
Returns
Type Parameters
MaxObj<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static T MaxObj<T>(this IEnumerable<T> enumeration, Func<T, float> distanceFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
distanceFunc |
|
Returns
Type Parameters
MaxOrDefault<T>(IEnumerable<T>, T)
Declaration
public static T MaxOrDefault<T>(this IEnumerable<T> container, T def = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
container |
|
T |
def |
|
Returns
Type Parameters
MaxOrDefault<T, TVal>(IEnumerable<T>, Func<T, TVal>, TVal)
Declaration
public static TVal MaxOrDefault<T, TVal>(this IEnumerable<T> container, Func<T, TVal> selector, TVal def = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
container |
|
System.Func<T, TVal> |
selector |
|
TVal |
def |
|
Returns
Type Parameters
MaxSet<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static IEnumerable<T> MaxSet<T>(this IEnumerable<T> enumeration, Func<T, float> valFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
valFunc |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
Returns median value for enumerable
. If sorted
is false
then it makes sorted copy of enumerable to find the median otherwise it just returns medium element.
Declaration
public static T Median<T>(this IEnumerable<T> enumerable, bool sorted = false)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Boolean |
sorted |
|
Returns
Type Parameters
MinIndex<T>(IEnumerable<T>)
Declaration
public static T MinIndex<T>(this IEnumerable<T> enumeration)
where T : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
Returns
Type Parameters
MinObj<T>(IEnumerable<T>, Func<T, Single>)
Returns first item with minimal value of distanceFunc
.
Declaration
public static T MinObj<T>(this IEnumerable<T> enumeration, Func<T, float> distanceFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
distanceFunc |
|
Returns
Type Parameters
MinObjAndDist<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static Nullable<(T, float)> MinObjAndDist<T>(this IEnumerable<T> enumeration, Func<T, float> distanceFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
distanceFunc |
|
Returns
Type |
Description |
System.Nullable<System.ValueTuple<T, System.Single>> |
|
Type Parameters
MinOrDefault<T>(IEnumerable<T>, T)
Declaration
public static T MinOrDefault<T>(this IEnumerable<T> container, T def = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
container |
|
T |
def |
|
Returns
Type Parameters
MinOrDefault<T, TVal>(IEnumerable<T>, Func<T, TVal>, TVal)
Declaration
public static TVal MinOrDefault<T, TVal>(this IEnumerable<T> container, Func<T, TVal> selector, TVal def = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
container |
|
System.Func<T, TVal> |
selector |
|
TVal |
def |
|
Returns
Type Parameters
MinRange<T>(IEnumerable<T>, Int32, IComparer<T>)
Returns up to n
minimal elements from enumerable
. From smallest to larger.
Declaration
public static T[] MinRange<T>(this IEnumerable<T> enumerable, int n, IComparer<T> comparer)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Int32 |
n |
|
System.Collections.Generic.IComparer<T> |
comparer |
|
Returns
Type Parameters
MinSet<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static IEnumerable<T> MinSet<T>(this IEnumerable<T> enumeration, Func<T, float> valFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
valFunc |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
Mult(IEnumerable<Single>)
Declaration
public static float Mult(this IEnumerable<float> list)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<System.Single> |
list |
|
Returns
Type |
Description |
System.Single |
|
None<T>(IEnumerable<T>, Func<T, Boolean>)
Declaration
public static bool None<T>(this IEnumerable<T> this, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
this |
|
System.Func<T, System.Boolean> |
predicate |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
NonNull<T>(IEnumerable<T>)
Declaration
public static IEnumerable<T> NonNull<T>(this IEnumerable<T> list)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
NullableExcept<T>(IEnumerable<T>, IEnumerable<T>)
Improved version of System.Linq.Enumerable.Except``1(System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEnumerable{``0}), but with nullable except
support. If it is null
then source
returned unmodified.
Declaration
public static IEnumerable<T> NullableExcept<T>(this IEnumerable<T> source, IEnumerable<T> except)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
System.Collections.Generic.IEnumerable<T> |
except |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
OfTypeList<T>(IEnumerable<T>, IEnumerable<Type>)
Declaration
public static IEnumerable<T> OfTypeList<T>(this IEnumerable<T> e, IEnumerable<Type> types)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
e |
|
System.Collections.Generic.IEnumerable<System.Type> |
types |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
ParallelForEach<T>(IEnumerable<T>, Action<T>)
Declaration
public static void ParallelForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Action<T> |
action |
|
Type Parameters
ParallelForEach<T, TContext>(IEnumerable<T>, TContext, Action<T, TContext>)
Calls parallel action for each element with context preferring no-alloc enumerator version (avoiding boxing).
Declaration
public static void ParallelForEach<T, TContext>(this IEnumerable<T> enumerable, TContext context, Action<T, TContext> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
enumerable.
|
TContext |
context |
context.
|
System.Action<T, TContext> |
action |
action.
|
Type Parameters
Name |
Description |
T |
item type.
|
TContext |
context type.
|
Random<T>(IEnumerable<T>)
Declaration
public static T Random<T>(this IEnumerable<T> enumerable)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
Returns
Type Parameters
Random<T>(IEnumerable<T>, Int32)
Declaration
public static IEnumerable<T> Random<T>(this IEnumerable<T> list, int entries)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Int32 |
entries |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
RandomExcept<T>(IEnumerable<T>, Int32)
Declaration
public static T RandomExcept<T>(this IEnumerable<T> enumerable, int i)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Int32 |
i |
|
Returns
Type Parameters
Range<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static Range Range<T>(this IEnumerable<T> enumeration, Func<T, float> func)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumeration |
|
System.Func<T, System.Single> |
func |
|
Returns
Type Parameters
Recursive<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
Declaration
public static IEnumerable<T> Recursive<T>(this IEnumerable<T> list, Func<T, IEnumerable<T>> getChildren)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Func<T, System.Collections.Generic.IEnumerable<T>> |
getChildren |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
RemoveNulls<T>(List<T>)
Declaration
public static void RemoveNulls<T>(this List<T> list)
where T : class
Parameters
Type |
Name |
Description |
System.Collections.Generic.List<T> |
list |
|
Type Parameters
Repeat<T>(Func<T>, Int32)
Declaration
public static IEnumerable<T> Repeat<T>(Func<T> func, int repeatCount)
Parameters
Type |
Name |
Description |
System.Func<T> |
func |
|
System.Int32 |
repeatCount |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
Replace<T>(IEnumerable<T>, T, T)
Declaration
public static IEnumerable<T> Replace<T>(this IEnumerable<T> source, T oldElement, T newElement)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
T |
oldElement |
|
T |
newElement |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
SelectFrom<TKey, TValue>(IEnumerable<TKey>, IDictionary<TKey, TValue>)
Declaration
public static IEnumerable<TValue> SelectFrom<TKey, TValue>(this IEnumerable<TKey> keys, IDictionary<TKey, TValue> dict)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TKey> |
keys |
|
System.Collections.Generic.IDictionary<TKey, TValue> |
dict |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TValue> |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
SelectFrom<T, TKey, TValue>(IEnumerable<T>, IDictionary<TKey, TValue>, Func<T, TKey>)
Declaration
public static IEnumerable<TValue> SelectFrom<T, TKey, TValue>(this IEnumerable<T> items, IDictionary<TKey, TValue> dict, Func<T, TKey> keyFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
|
System.Collections.Generic.IDictionary<TKey, TValue> |
dict |
|
System.Func<T, TKey> |
keyFunc |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TValue> |
|
Type Parameters
Name |
Description |
T |
|
TKey |
|
TValue |
|
SelectNonNull<T, TResult>(IEnumerable<T>, Func<T, TResult>, TResult)
Declaration
public static IEnumerable<TResult> SelectNonNull<T, TResult>(this IEnumerable<T> sequence, Func<T, TResult> projection, TResult ifEmpty = null)
where TResult : class
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
sequence |
|
System.Func<T, TResult> |
projection |
|
TResult |
ifEmpty |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TResult> |
|
Type Parameters
Name |
Description |
T |
|
TResult |
|
SequenceEqualNullSafe<T>(IEnumerable<T>, IEnumerable<T>)
Declaration
public static bool SequenceEqualNullSafe<T>(this IEnumerable<T> left, IEnumerable<T> right)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
left |
|
System.Collections.Generic.IEnumerable<T> |
right |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
Shuffle<T>(IEnumerable<T>)
Declaration
public static T[] Shuffle<T>(this IEnumerable<T> enumerable)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
Returns
Type Parameters
SingleItemAsEnumerable<T>(T)
Declaration
public static IEnumerable<T> SingleItemAsEnumerable<T>(this T item)
Parameters
Type |
Name |
Description |
T |
item |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
Swap<T>(IEnumerable<T>, T, T)
Declaration
public static IEnumerable<T> Swap<T>(this IEnumerable<T> source, T element1, T element2)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
T |
element1 |
|
T |
element2 |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
TakeUntilIncluding<T>(IEnumerable<T>, Func<T, Boolean>)
Declaration
public static IEnumerable<T> TakeUntilIncluding<T>(this IEnumerable<T> list, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
list |
|
System.Func<T, System.Boolean> |
predicate |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
ToBson(IEnumerable, in BsonSerializationContext, Boolean)
Declaration
public static BSONArray ToBson(this IEnumerable enumeration, in BsonSerializationContext context = null, bool doAllParams = false)
Parameters
Type |
Name |
Description |
System.Collections.IEnumerable |
enumeration |
|
BsonSerializationContext |
context |
|
System.Boolean |
doAllParams |
|
Returns
ToDictionaryNonNullKeys<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)
Declaration
public static Dictionary<TKey, TElement> ToDictionaryNonNullKeys<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<TSource, TKey> |
keySelector |
|
System.Func<TSource, TElement> |
elementSelector |
|
Returns
Type |
Description |
System.Collections.Generic.Dictionary<TKey, TElement> |
|
Type Parameters
Name |
Description |
TSource |
|
TKey |
|
TElement |
|
ToDictionaryWithDistinctKeys<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)
Same as ToDictionary, but only adds entry with first distinct key.
Declaration
public static Dictionary<TKey, TElement> ToDictionaryWithDistinctKeys<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<TSource, TKey> |
keySelector |
|
System.Func<TSource, TElement> |
elementSelector |
|
Returns
Type |
Description |
System.Collections.Generic.Dictionary<TKey, TElement> |
|
Type Parameters
Name |
Description |
TSource |
|
TKey |
|
TElement |
|
TryGetFirst<T>(IEnumerable<T>, out T)
Tries to get first element from enumerable (if exists).
Declaration
public static bool TryGetFirst<T>(this IEnumerable<T> enumerable, out T element)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
T |
element |
|
Returns
Type |
Description |
System.Boolean |
true if enumerable is not empty and element contains the first element, false otherwise.
|
Type Parameters
TryGetFirst<T>(IEnumerable<T>, Func<T, Boolean>, out T)
Gets the first value matching predicate
into an out var, returning true if found.
Declaration
public static bool TryGetFirst<T>(this IEnumerable<T> enumerable, Func<T, bool> predicate, out T val)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Func<T, System.Boolean> |
predicate |
|
T |
val |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
TryGetMinBy<TKey, TValue>(IEnumerable<TKey>, Func<TKey, TValue>, out (TKey, TValue))
Tries to get minimal element from enumerable
if it has elements. Returns false
otherwise.
Declaration
public static bool TryGetMinBy<TKey, TValue>(this IEnumerable<TKey> enumerable, Func<TKey, TValue> valueSelector, out (TKey, TValue) result)
where TValue : struct, ValueType
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TKey> |
enumerable |
|
System.Func<TKey, TValue> |
valueSelector |
|
System.ValueTuple<TKey, TValue> |
result |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
TryGetSingle<T>(IEnumerable<T>, out T)
Gets the single value into an out var, returning true if found only one value.
Declaration
public static bool TryGetSingle<T>(this IEnumerable<T> enumerable, out T val)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
T |
val |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
TryGetSingle<T>(IEnumerable<T>, Func<T, Boolean>, out T)
Gets the single value matching predicate
into an out var, returning true if found only one value.
Declaration
public static bool TryGetSingle<T>(this IEnumerable<T> enumerable, Func<T, bool> predicate, out T val)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Func<T, System.Boolean> |
predicate |
|
T |
val |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
WeightedAverage<T>(IEnumerable<T>, Func<T, Single>, Func<T, Single>)
Declaration
public static float WeightedAverage<T>(this IEnumerable<T> records, Func<T, float> value, Func<T, float> weight)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
records |
|
System.Func<T, System.Single> |
value |
|
System.Func<T, System.Single> |
weight |
|
Returns
Type |
Description |
System.Single |
|
Type Parameters
WeightedRandom<T>(IEnumerable<T>, Func<T, Single>)
Declaration
public static T WeightedRandom<T>(this IEnumerable<T> enumerable, Func<T, float> weightFunc)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Func<T, System.Single> |
weightFunc |
|
Returns
Type Parameters
WeightedRandom<T>(IEnumerable<T>, Func<T, Single>, Int32)
Declaration
public static IEnumerable<T> WeightedRandom<T>(this IEnumerable<T> enumerable, Func<T, float> weightFunc, int numToSelect)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
enumerable |
|
System.Func<T, System.Single> |
weightFunc |
|
System.Int32 |
numToSelect |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters