Class EnumerableExtensions
Extensions for enumerable sources
Inheritance
System.Object
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
public static class EnumerableExtensions
Methods
ContainsAll<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)
Returns true if all items in the other collection exist in this collection
Declaration
public static bool ContainsAll<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> other)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Collections.Generic.IEnumerable<TSource> |
other |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
ContainsAny<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)
Returns true if the source contains any of the items in the other list
Declaration
public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> other)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Collections.Generic.IEnumerable<TSource> |
other |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
DistinctBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)
Declaration
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)where TKey : IEquatable<TKey>
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
The source.
|
System.Func<TSource, TKey> |
keySelector |
The key selector.
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TSource> |
the unique list
|
Type Parameters
Name |
Description |
TSource |
Source type
|
TKey |
Key type
|
FindIndex<T>(IEnumerable<T>, Func<T, Boolean>)
Finds the index of the first item matching an expression in an enumerable.
Declaration
public static int FindIndex<T>(this IEnumerable<T> items, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
The enumerable to search.
|
System.Func<T, System.Boolean> |
predicate |
The expression to test the items against.
|
Returns
Type |
Description |
System.Int32 |
The index of the first matching item, or -1.
|
Type Parameters
Name |
Description |
T |
The type of the enumerated objects.
|
FindIndex<T>(IEnumerable<T>, Int32, Func<T, Boolean>)
Finds the index of the first item matching an expression in an enumerable.
Declaration
public static int FindIndex<T>(this IEnumerable<T> items, int startIndex, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
The enumerable to search.
|
System.Int32 |
startIndex |
The index to start at.
|
System.Func<T, System.Boolean> |
predicate |
The expression to test the items against.
|
Returns
Type |
Description |
System.Int32 |
The index of the first matching item, or -1.
|
Type Parameters
Name |
Description |
T |
The type of the enumerated objects.
|
FlattenList<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
Declaration
[Obsolete("Do not use, use SelectRecursive instead which has far less potential of re-iterating an iterator which may cause significantly more SQL queries")]
public static IEnumerable<T> FlattenList<T>(this IEnumerable<T> e, Func<T, IEnumerable<T>> f)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
e |
The items.
|
System.Func<T, System.Collections.Generic.IEnumerable<T>> |
f |
The select child.
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
list of TItem
|
Type Parameters
Name |
Description |
T |
Item type
|
ForAllThatAre<TBase, TActual>(IEnumerable<TBase>, Action<TActual>)
Declaration
public static IEnumerable<TBase> ForAllThatAre<TBase, TActual>(this IEnumerable<TBase> sequence, Action<TActual> projection)where TActual : class
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TBase> |
sequence |
|
System.Action<TActual> |
projection |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TBase> |
|
Type Parameters
Name |
Description |
TBase |
|
TActual |
|
ForEach<TItem>(IEnumerable<TItem>, Action<TItem>)
Declaration
[Obsolete("Use a normal foreach loop instead, this adds more allocations than necessary")]
public static IEnumerable<TItem> ForEach<TItem>(this IEnumerable<TItem> items, Action<TItem> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TItem> |
items |
|
System.Action<TItem> |
action |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TItem> |
|
Type Parameters
ForEach<TItem, TResult>(IEnumerable<TItem>, Func<TItem, TResult>)
Declaration
[Obsolete("Use a normal foreach loop instead, this adds more allocations than necessary")]
public static TResult[] ForEach<TItem, TResult>(this IEnumerable<TItem> items, Func<TItem, TResult> func)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TItem> |
items |
|
System.Func<TItem, TResult> |
func |
|
Returns
Type |
Description |
TResult[] |
|
Type Parameters
Name |
Description |
TItem |
|
TResult |
|
IfNotNull<TItem>(IEnumerable<TItem>, Action<TItem>)
Declaration
public static void IfNotNull<TItem>(this IEnumerable<TItem> items, Action<TItem> action)where TItem : class
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TItem> |
items |
The items.
|
System.Action<TItem> |
action |
The action.
|
Type Parameters
Name |
Description |
TItem |
The type
|
IndexOf<T>(IEnumerable<T>, T)
Finds the index of the first occurence of an item in an enumerable.
Declaration
public static int IndexOf<T>(this IEnumerable<T> items, T item)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
The enumerable to search.
|
T |
item |
The item to find.
|
Returns
Type |
Description |
System.Int32 |
The index of the first matching item, or -1 if the item was not found.
|
Type Parameters
InGroupsOf<T>(IEnumerable<T>, Int32)
Declaration
public static IEnumerable<IEnumerable<T>> InGroupsOf<T>(this IEnumerable<T> source, int groupSize)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
System.Int32 |
groupSize |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<T>> |
|
Type Parameters
Range<T>(Func<Int32, T>, Int32)
Returns a sequence of length count whose elements are the result of invoking factory.
Declaration
public static IEnumerable<T> Range<T>(Func<int, T> factory, int count)
Parameters
Type |
Name |
Description |
System.Func<System.Int32, T> |
factory |
The factory.
|
System.Int32 |
count |
The count.
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
RemoveAll<T>(ICollection<T>, Func<T, Boolean>)
Removes all matching items from an System.Collections.Generic.ICollection<T>.
Declaration
public static void RemoveAll<T>(this ICollection<T> list, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.ICollection<T> |
list |
The list.
|
System.Func<T, System.Boolean> |
predicate |
The predicate.
|
Type Parameters
RemoveAll<T>(IList<T>, Func<T, Boolean>)
Removes all matching items from an System.Collections.Generic.IList<T>.
Declaration
public static void RemoveAll<T>(this IList<T> list, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<T> |
list |
The list.
|
System.Func<T, System.Boolean> |
predicate |
The predicate.
|
Type Parameters
SelectRecursive<TSource>(IEnumerable<TSource>, Func<TSource, IEnumerable<TSource>>, Int32)
Declaration
public static IEnumerable<TSource> SelectRecursive<TSource>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TSource>> recursiveSelector, int maxRecusionDepth = 100)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<TSource, System.Collections.Generic.IEnumerable<TSource>> |
recursiveSelector |
|
System.Int32 |
maxRecusionDepth |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TSource> |
|
Type Parameters
SkipLast<T>(IEnumerable<T>)
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
UnsortedSequenceEqual<T>(IEnumerable<T>, IEnumerable<T>)
Determines if 2 lists have equal elements within them regardless of how they are sorted
Declaration
public static bool UnsortedSequenceEqual<T>(this IEnumerable<T> source, IEnumerable<T> other)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
System.Collections.Generic.IEnumerable<T> |
other |
|
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
WhereNotNull<T>(IEnumerable<T>)
Filters a sequence of values to ignore those which are null.
Declaration
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> coll)where T : class
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
coll |
The coll.
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters