Search Results for

    Show / Hide Table of Contents

    Class CollectionExtensions

    Inheritance
    object
    CollectionExtensions
    Namespace: TetraCreations.Core
    Assembly: cs.temp.dll.dll
    Syntax
    public static class CollectionExtensions

    Methods

    AddIf<T>(ICollection<T>, T, Func<T, bool>)

    Add an element to the collection depending on a predicate function

    Declaration
    public static bool AddIf<T>(this ICollection<T> collection, T element, Func<T, bool> predicate)
    Parameters
    Type Name Description
    ICollection<><T> collection
    T element

    The element to add

    Func<, ><T, bool> predicate

    Predicate function needs to return true to add the element

    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    AddIfNotContains<T>(ICollection<T>, T)

    Add the T value to the collection if it doesn't already exists inside

    Declaration
    public static bool AddIfNotContains<T>(this ICollection<T> collection, T value)
    Parameters
    Type Name Description
    ICollection<><T> collection
    T value
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    AddIfNotNull<T>(ICollection<T>, T)

    Add the T element to the collection if it's not null

    Declaration
    public static bool AddIfNotNull<T>(this ICollection<T> collection, T element)
    Parameters
    Type Name Description
    ICollection<><T> collection
    T element
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    AsString<T>(IList<T>, string)

    Return the list content as a string

    Declaration
    public static string AsString<T>(this IList<T> list, string separator = ", ")
    Parameters
    Type Name Description
    IList<><T> list
    string separator
    Returns
    Type Description
    string
    Type Parameters
    Name Description
    T

    GetOrDefault<T>(T[], int)

    Returns T from the index if it exist otherwise default(T)

    Declaration
    public static T GetOrDefault<T>(this T[] array, int index)
    Parameters
    Type Name Description
    T[] array
    int index
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetRandomElement<T>(IList<T>)

    Returns a random element from a list. Sampling with replacement.

    Declaration
    public static T GetRandomElement<T>(this IList<T> list)
    Parameters
    Type Name Description
    IList<><T> list
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    HasUniqueElements<T>(ICollection<T>, IEqualityComparer<T>)

    Determines if the collection contains only unique elements using a custom IEqualityComparer

    Declaration
    public static bool HasUniqueElements<T>(this ICollection<T> collection, IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    ICollection<><T> collection
    IEqualityComparer<><T> comparer
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    HasUniqueElements<T>(ICollection<T>)

    Determines if the collection contains only unique elements

    Declaration
    public static bool HasUniqueElements<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    IndexInRange<T>(T[], int)

    Returns true if the index exist in the array

    Declaration
    public static bool IndexInRange<T>(this T[] array, int index)
    Parameters
    Type Name Description
    T[] array
    int index
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    IsEmpty<T>(ICollection<T>)

    Determines if the collection is empty

    Declaration
    public static bool IsEmpty<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    IsNotEmpty<T>(ICollection<T>)

    Determines if the collection is not empty

    Declaration
    public static bool IsNotEmpty<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    IsNotNullOrEmpty<T>(ICollection<T>)

    Determines if the collection is not null or empty

    Declaration
    public static bool IsNotNullOrEmpty<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    IsNullOrEmpty<T>(ICollection<T>)

    Determines if the collection is null or empty

    Declaration
    public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    Log<T>(ICollection<T>)

    Displays the content of the Collection in the console

    Declaration
    public static void Log<T>(this ICollection<T> collection)
    Parameters
    Type Name Description
    ICollection<><T> collection
    Type Parameters
    Name Description
    T

    LogArray<T>(T[])

    Debug.Log all elements from the array

    Declaration
    public static void LogArray<T>(T[] array)
    Parameters
    Type Name Description
    T[] array
    Type Parameters
    Name Description
    T

    RemoveRandomElement<T>(IList<T>)

    Removes a random element from a list, returning that item.

    Declaration
    public static T RemoveRandomElement<T>(this IList<T> list)
    Parameters
    Type Name Description
    IList<><T> list
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    ReverseLoop<T>(IList<T>)

    Loop backwards, useful to delete an element from the list.

    Declaration
    public static IEnumerable<T> ReverseLoop<T>(this IList<T> list)
    Parameters
    Type Name Description
    IList<><T> list
    Returns
    Type Description
    IEnumerable<><T>
    Type Parameters
    Name Description
    T

    Shuffle<T>(IList<T>)

    Shuffles the elements of a list randomly using fischer yates algorithm.
    The algorithm produces an unbiased permutation.
    Source: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

    Declaration
    public static void Shuffle<T>(this IList<T> list)
    Parameters
    Type Name Description
    IList<><T> list

    The list to Shuffle

    Type Parameters
    Name Description
    T

    WithoutDuplicates<T>(ICollection<T>)

    Declaration
    public static List<T> WithoutDuplicates<T>(this ICollection<T> list)
    Parameters
    Type Name Description
    ICollection<><T> list
    Returns
    Type Description
    List<><T>
    Type Parameters
    Name Description
    T
    In This Article
    Back to top Tetra Creations documentation