View Source
Class EnumerableExtensions
Extensions for enumerable sources
Inheritance
System.Object
Assembly: Umbraco.Core.dll
Syntax
public static class EnumerableExtensions
Methods
View Source
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
View Source
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
View Source
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
|
View Source
EmptyNull<T>(IEnumerable<T>)
Gets a null IEnumerable as an empty IEnumerable.
Declaration
public static IEnumerable<T> EmptyNull<T>(this IEnumerable<T> items)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
items |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
View Source
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.
|
View Source
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.
|
View Source
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 |
|
View Source
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
|
View Source
IndexOf<T>(IEnumerable<T>, T)
Finds the index of the first occurrence 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
View Source
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
View Source
OfTypes<T>(IEnumerable<T>, Type[])
Declaration
public static IEnumerable<T> OfTypes<T>(this IEnumerable<T> contents, params Type[] types)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
contents |
|
System.Type[] |
types |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
View Source
OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, Direction)
Declaration
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Direction sortOrder)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<TSource, TKey> |
keySelector |
|
Direction |
sortOrder |
|
Returns
Type |
Description |
System.Linq.IOrderedEnumerable<TSource> |
|
Type Parameters
Name |
Description |
TSource |
|
TKey |
|
View Source
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
View Source
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
View Source
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
View Source
SelectByGroups<TResult, TSource>(IEnumerable<TSource>, Func<IEnumerable<TSource>, IEnumerable<TResult>>, Int32)
Declaration
public static IEnumerable<TResult> SelectByGroups<TResult, TSource>(this IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector, int groupSize)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<System.Collections.Generic.IEnumerable<TSource>, System.Collections.Generic.IEnumerable<TResult>> |
selector |
|
System.Int32 |
groupSize |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TResult> |
|
Type Parameters
Name |
Description |
TResult |
|
TSource |
|
View Source
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
View Source
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
View Source
Transforms an enumerable.
Declaration
public static IEnumerable<TTarget> Transform<TSource, TTarget>(this IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TTarget>> transform)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TSource> |
source |
|
System.Func<System.Collections.Generic.IEnumerable<TSource>, System.Collections.Generic.IEnumerable<TTarget>> |
transform |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TTarget> |
|
Type Parameters
Name |
Description |
TSource |
|
TTarget |
|
View Source
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
View Source
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
View Source
Yield<T>(T)
Wraps this object instance into an IEnumerable{T} consisting of a single item.
Declaration
public static IEnumerable<T> Yield<T>(this T item)
Parameters
Type |
Name |
Description |
T |
item |
The instance that will be wrapped.
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
An IEnumerable{T} consisting of a single item.
|
Type Parameters
Name |
Description |
T |
Type of the object.
|