Search Results for

    Show / Hide Table of Contents

    Class CollectionExtensions

    Defines a collection of extensions for enumerables, lists, and collections.

    Inheritance
    System.Object
    CollectionExtensions
    Namespace: MADE.Collections
    Assembly: MADE.Collections.dll
    Syntax
    public static class CollectionExtensions : object

    Methods

    | Improve this Doc View Source

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

    Adds the specified item to the collection based on the specified condition being true.

    Declaration
    public static void AddIf<T>(this IList<T> collection, T item, Func<bool> condition)
    Parameters
    Type Name Description
    IList<T> collection

    The collection to add the item to.

    T item

    The item to add.

    Func<System.Boolean> condition

    The condition required to add the item.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    | Improve this Doc View Source

    AddRange<T>(ICollection<T>, IEnumerable<T>)

    Adds a collection of items to another.

    Declaration
    public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> itemsToAdd)
    Parameters
    Type Name Description
    ICollection<T> collection

    The collection to add to.

    IEnumerable<T> itemsToAdd

    The items to add.

    Type Parameters
    Name Description
    T

    The type of items in the collection.

    Exceptions
    Type Condition
    System.ArgumentNullException

    The collection or itemsToAdd is null.

    | Improve this Doc View Source

    AddRangeIf<T>(ICollection<T>, IEnumerable<T>, Func<Boolean>)

    Adds the specified collection of items to the collection based on the specified condition being true.

    Declaration
    public static void AddRangeIf<T>(this ICollection<T> collection, IEnumerable<T> itemsToAdd, Func<bool> condition)
    Parameters
    Type Name Description
    ICollection<T> collection

    The collection to add the items to.

    IEnumerable<T> itemsToAdd

    The items to add.

    Func<System.Boolean> condition

    The condition required to add the items.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    | Improve this Doc View Source

    AreEquivalent<T>(ICollection<T>, ICollection<T>)

    Determines whether two collections are equivalent, containing all the same items with no regard to order.

    Declaration
    public static bool AreEquivalent<T>(this ICollection<T> expected, ICollection<T> actual)
    Parameters
    Type Name Description
    ICollection<T> expected

    The expected collection.

    ICollection<T> actual

    The actual collection.

    Returns
    Type Description
    System.Boolean

    True if the collections are equivalent; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of item.

    | Improve this Doc View Source

    Chunk<T>(IEnumerable<T>, Int32)

    Chunks a collection of items into a collection of collections grouped into the specified chunk size.

    Declaration
    public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunkSize = 25)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source collection to chunk.

    System.Int32 chunkSize

    The chunk size.

    Returns
    Type Description
    IEnumerable<IEnumerable<T>>

    A collection of collections containing the chunked items.

    Type Parameters
    Name Description
    T

    The type of item.

    | Improve this Doc View Source

    ForEach<T>(IEnumerable<T>, Action<T>)

    Performs the specified action on each item in the collection.

    Declaration
    public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
    Parameters
    Type Name Description
    IEnumerable<T> collection

    The collection to action on.

    Action<T> action

    The action to perform.

    Type Parameters
    Name Description
    T

    The type of item in the collection.

    | Improve this Doc View Source

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

    Inserts an item to the specified source at the potential index determined by the predicate.

    Declaration
    public static int InsertAtPotentialIndex<T>(this IList<T> source, T value, Func<T, T, bool> predicate)
    Parameters
    Type Name Description
    IList<T> source

    The source where the value should be inserted.

    T value

    The object to insert into the source.

    Func<T, T, System.Boolean> predicate

    The action to run to determine the position of the item based on the provided value and an item in the collection.

    Returns
    Type Description
    System.Int32

    The inserted index of the item.

    Type Parameters
    Name Description
    T

    The type of items in the collection.

    Exceptions
    Type Condition
    System.NotSupportedException

    The System.Collections.Generic.IList`1 is read-only.

    | Improve this Doc View Source

    IsNullOrEmpty<T>(IEnumerable<T>)

    Indicates whether the specified collection is null or empty (containing no items).

    Declaration
    public static bool IsNullOrEmpty<T>(this IEnumerable<T> source)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The collection to test.

    Returns
    Type Description
    System.Boolean

    true if the source parameter is null or empty (containing no items); otherwise, false.

    Type Parameters
    Name Description
    T

    The type of item in the collection.

    | Improve this Doc View Source

    MakeEqualTo<T>(ICollection<T>, IEnumerable<T>)

    Makes the given destination collection items equal to the items in the given source collection by adding or removing items from the destination.

    Declaration
    public static void MakeEqualTo<T>(this ICollection<T> destination, IEnumerable<T> source)
    Parameters
    Type Name Description
    ICollection<T> destination

    The destination collection to add or remove items to.

    IEnumerable<T> source

    The source collection to provide the items.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    | Improve this Doc View Source

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

    Gets the potential index of an item that does not currently exist within a collection based on the specified criteria.

    Declaration
    public static int PotentialIndexOf<T>(this IList<T> source, T value, Func<T, T, bool> predicate)
    Parameters
    Type Name Description
    IList<T> source

    The collection to get the index from.

    T value

    The object to determine an index for in the source.

    Func<T, T, System.Boolean> predicate

    The action to run to determine the position of the item based on the provided value and an item in the collection.

    Returns
    Type Description
    System.Int32

    The potential index of the item.

    Type Parameters
    Name Description
    T

    The type of items in the collection.

    | Improve this Doc View Source

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

    Removes the specified item from the collection based on the specified condition being true.

    Declaration
    public static void RemoveIf<T>(this IList<T> collection, T item, Func<bool> condition)
    Parameters
    Type Name Description
    IList<T> collection

    The collection to remove the item from.

    T item

    The item to remove.

    Func<System.Boolean> condition

    The condition required to remove the item.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    | Improve this Doc View Source

    RemoveRange<T>(ICollection<T>, IEnumerable<T>)

    Removes a collection of items from another.

    Declaration
    public static void RemoveRange<T>(this ICollection<T> collection, IEnumerable<T> itemsToRemove)
    Parameters
    Type Name Description
    ICollection<T> collection

    The collection to remove from.

    IEnumerable<T> itemsToRemove

    The items to remove from the collection.

    Type Parameters
    Name Description
    T

    The type of items in the collection.

    Exceptions
    Type Condition
    System.ArgumentNullException

    The collection or itemsToRemove is null.

    | Improve this Doc View Source

    RemoveRangeIf<T>(ICollection<T>, IEnumerable<T>, Func<Boolean>)

    Removes the specified collection of items from the collection based on the specified condition being true.

    Declaration
    public static void RemoveRangeIf<T>(this ICollection<T> collection, IEnumerable<T> itemsToRemove, Func<bool> condition)
    Parameters
    Type Name Description
    ICollection<T> collection

    The collection to remove the items from.

    IEnumerable<T> itemsToRemove

    The items to remove.

    Func<System.Boolean> condition

    The condition required to remove the items.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    | Improve this Doc View Source

    Shuffle<T>(IEnumerable<T>)

    Shuffles the elements of a sequence randomly.

    Declaration
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The collection to shuffle.

    Returns
    Type Description
    IEnumerable<T>

    The shuffled collection of items.

    Type Parameters
    Name Description
    T

    The type of item in the collection.

    | Improve this Doc View Source

    Sort<T, TKey>(ObservableCollection<T>, Func<T, TKey>)

    Sorts the elements in the entire using the specified comparer.

    Declaration
    public static void Sort<T, TKey>(this ObservableCollection<T> source, Func<T, TKey> comparer)
    Parameters
    Type Name Description
    ObservableCollection<T> source

    The source collection to sort.

    Func<T, TKey> comparer

    The implementation to use when comparing elements.

    Type Parameters
    Name Description
    T

    The type of item in the collection.

    TKey

    The key value of the item to sort on.

    | Improve this Doc View Source

    SortDescending<T, TKey>(ObservableCollection<T>, Func<T, TKey>)

    Sorts the elements in the entire using the specified comparer in descending order.

    Declaration
    public static void SortDescending<T, TKey>(this ObservableCollection<T> source, Func<T, TKey> comparer)
    Parameters
    Type Name Description
    ObservableCollection<T> source

    The source collection to sort.

    Func<T, TKey> comparer

    The implementation to use when comparing elements.

    Type Parameters
    Name Description
    T

    The type of item in the collection.

    TKey

    The key value of the item to sort on.

    | Improve this Doc View Source

    TakeFrom<T>(List<T>, Int32, Int32)

    Takes a number of elements from the specified collection from the specified starting index.

    Declaration
    public static IEnumerable<T> TakeFrom<T>(this List<T> list, int startingIndex, int takeCount)
    Parameters
    Type Name Description
    List<T> list

    The to take items from.

    System.Int32 startingIndex

    The index to start at in the .

    System.Int32 takeCount

    The number of items to take from the starting index of the .

    Returns
    Type Description
    IEnumerable<T>

    A collection of T items.

    Type Parameters
    Name Description
    T

    The type of elements in the collection.

    | Improve this Doc View Source

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

    Updates an item within the collection.

    Declaration
    public static bool Update<T>(this IList<T> collection, T item, Func<T, T, bool> predicate)
    Parameters
    Type Name Description
    IList<T> collection

    The collection to update an item in.

    T item

    The item to update.

    Func<T, T, System.Boolean> predicate

    The function to find the item within the collection.

    Returns
    Type Description
    System.Boolean

    True if the item has been updated; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of item within the collection.

    Exceptions
    Type Condition
    System.ArgumentNullException

    The item or collection is null.

    System.Exception

    The predicate delegate callback throws an exception.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright (c) MADE Apps