Search Results for

    Show / Hide Table of Contents
    View Source

    Class EnumerableExtensions

    Extensions for enumerable sources

    Inheritance
    System.Object
    Namespace: Umbraco.Extensions
    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
    IEnumerable<TSource> source
    IEnumerable<TSource> other
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    TSource
    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
    IEnumerable<TSource> source
    IEnumerable<TSource> other
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    TSource
    View Source

    EmptyNull<T>(Nullable<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.Nullable<IEnumerable<T>> items
    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    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
    IEnumerable<T> items

    The enumerable to search.

    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
    IEnumerable<T> items

    The enumerable to search.

    System.Int32 startIndex

    The index to start at.

    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
    IEnumerable<TBase> sequence
    Action<TActual> projection
    Returns
    Type Description
    IEnumerable<TBase>
    Type Parameters
    Name Description
    TBase
    TActual
    View Source

    IfNotNull<TItem>(IEnumerable<TItem>, Action<TItem>)

    The if not null.

    Declaration
    public static void IfNotNull<TItem>(this IEnumerable<TItem> items, Action<TItem> action)
        where TItem : class
    Parameters
    Type Name Description
    IEnumerable<TItem> items

    The items.

    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
    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
    Name Description
    T
    View Source

    InGroupsOf<T>(Nullable<IEnumerable<T>>, Int32)

    Declaration
    public static IEnumerable<IEnumerable<T>> InGroupsOf<T>(this IEnumerable<T>? source, int groupSize)
    Parameters
    Type Name Description
    System.Nullable<IEnumerable<T>> source
    System.Int32 groupSize
    Returns
    Type Description
    IEnumerable<IEnumerable<T>>
    Type Parameters
    Name Description
    T
    View Source

    IsCollectionEmpty<T>(Nullable<IReadOnlyCollection<T>>)

    Declaration
    public static bool IsCollectionEmpty<T>(this IReadOnlyCollection<T>? list)
    Parameters
    Type Name Description
    System.Nullable<IReadOnlyCollection<T>> list
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    T
    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
    IEnumerable<T> contents
    Type[] types
    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    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
    IEnumerable<TSource> source
    Func<TSource, TKey> keySelector
    Direction sortOrder
    Returns
    Type Description
    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
    Func<System.Int32, T> factory

    The factory.

    System.Int32 count

    The count.

    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    View Source

    RemoveAll<T>(ICollection<T>, Func<T, Boolean>)

    Removes all matching items from an .

    Declaration
    public static void RemoveAll<T>(this ICollection<T> list, Func<T, bool> predicate)
    Parameters
    Type Name Description
    ICollection<T> list

    The list.

    Func<T, System.Boolean> predicate

    The predicate.

    Type Parameters
    Name Description
    T
    View Source

    RemoveAll<T>(IList<T>, Func<T, Boolean>)

    Removes all matching items from an .

    Declaration
    public static void RemoveAll<T>(this IList<T> list, Func<T, bool> predicate)
    Parameters
    Type Name Description
    IList<T> list

    The list.

    Func<T, System.Boolean> predicate

    The predicate.

    Type Parameters
    Name Description
    T
    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
    IEnumerable<TSource> source
    Func<IEnumerable<TSource>, IEnumerable<TResult>> selector
    System.Int32 groupSize
    Returns
    Type Description
    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
    IEnumerable<TSource> source
    Func<TSource, IEnumerable<TSource>> recursiveSelector
    System.Int32 maxRecusionDepth
    Returns
    Type Description
    IEnumerable<TSource>
    Type Parameters
    Name Description
    TSource
    View Source

    SkipLast<T>(IEnumerable<T>)

    Declaration
    public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source)
    Parameters
    Type Name Description
    IEnumerable<T> source
    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    View Source

    Transform<TSource, TTarget>(IEnumerable<TSource>, Func<IEnumerable<TSource>, IEnumerable<TTarget>>)

    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
    IEnumerable<TSource> source
    Func<IEnumerable<TSource>, IEnumerable<TTarget>> transform
    Returns
    Type Description
    IEnumerable<TTarget>
    Type Parameters
    Name Description
    TSource
    TTarget
    View Source

    UnsortedSequenceEqual<T>(Nullable<IEnumerable<T>>, Nullable<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.Nullable<IEnumerable<T>> source
    System.Nullable<IEnumerable<T>> other
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    T
    Remarks

    The logic for this is taken from: http://stackoverflow.com/questions/4576723/test-whether-two-ienumerablet-have-the-same-values-with-the-same-frequencies There's a few answers, this one seems the best for it's simplicity and based on the comment of Eamon

    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
    IEnumerable<T> coll

    The coll.

    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    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
    IEnumerable<T>

    An IEnumerable{T} consisting of a single item.

    Type Parameters
    Name Description
    T

    Type of the object.

    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • ContainsAll<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)
      • ContainsAny<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)
      • EmptyNull<T>(Nullable<IEnumerable<T>>)
      • FindIndex<T>(IEnumerable<T>, Func<T, Boolean>)
      • FindIndex<T>(IEnumerable<T>, Int32, Func<T, Boolean>)
      • ForAllThatAre<TBase, TActual>(IEnumerable<TBase>, Action<TActual>)
      • IfNotNull<TItem>(IEnumerable<TItem>, Action<TItem>)
      • IndexOf<T>(IEnumerable<T>, T)
      • InGroupsOf<T>(Nullable<IEnumerable<T>>, Int32)
      • IsCollectionEmpty<T>(Nullable<IReadOnlyCollection<T>>)
      • OfTypes<T>(IEnumerable<T>, Type[])
      • OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, Direction)
      • Range<T>(Func<Int32, T>, Int32)
      • RemoveAll<T>(ICollection<T>, Func<T, Boolean>)
      • RemoveAll<T>(IList<T>, Func<T, Boolean>)
      • SelectByGroups<TResult, TSource>(IEnumerable<TSource>, Func<IEnumerable<TSource>, IEnumerable<TResult>>, Int32)
      • SelectRecursive<TSource>(IEnumerable<TSource>, Func<TSource, IEnumerable<TSource>>, Int32)
      • SkipLast<T>(IEnumerable<T>)
      • Transform<TSource, TTarget>(IEnumerable<TSource>, Func<IEnumerable<TSource>, IEnumerable<TTarget>>)
      • UnsortedSequenceEqual<T>(Nullable<IEnumerable<T>>, Nullable<IEnumerable<T>>)
      • WhereNotNull<T>(IEnumerable<T>)
      • Yield<T>(T)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX