Search Results for

    Show / Hide Table of Contents

    Class CollectionExtensions

    Inheritance
    object
    CollectionExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Glitch9
    Assembly: Glitch9.dll
    Syntax
    public static class CollectionExtensions

    Methods

    | Edit this page View Source

    AddOrUpdate<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)

    Adds a key-value pair to the dictionary or updates the value if the key already exists.

    Declaration
    public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue value)
    Parameters
    Type Name Description
    IDictionary<TKey, TValue> dict
    TKey key
    TValue value
    Type Parameters
    Name Description
    TKey
    TValue
    | Edit this page View Source

    ContainsAll<T>(IEnumerable<T>, IEnumerable<T>)

    Declaration
    public static bool ContainsAll<T>(this IEnumerable<T> ie, IEnumerable<T> values)
    Parameters
    Type Name Description
    IEnumerable<T> ie
    IEnumerable<T> values
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    ContainsAnyFlag<TFlagKey, TValue>(IDictionary<TFlagKey, TValue>, TFlagKey)

    Declaration
    public static bool ContainsAnyFlag<TFlagKey, TValue>(this IDictionary<TFlagKey, TValue> dict, TFlagKey flags) where TFlagKey : struct, Enum
    Parameters
    Type Name Description
    IDictionary<TFlagKey, TValue> dict
    TFlagKey flags
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    TFlagKey
    TValue
    | Edit this page View Source

    ContainsAny<T>(IEnumerable<T>, params T[])

    Declaration
    public static bool ContainsAny<T>(this IEnumerable<T> ie, params T[] values)
    Parameters
    Type Name Description
    IEnumerable<T> ie
    T[] values
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    GetBestMatch<T>(Dictionary<string, T>, string, Action<string>)

    Gets the best matching value from the dictionary based on the provided key. If no match is found, invokes the onNotFound action if provided.

    Declaration
    public static T GetBestMatch<T>(this Dictionary<string, T> dict, string key, Action<string> onNotFound = null)
    Parameters
    Type Name Description
    Dictionary<string, T> dict
    string key
    Action<string> onNotFound
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    IndexOf<T>(IEnumerable<T>, Func<T, bool>)

    Finds the index of the first element in the collection that matches the specified predicate.

    Declaration
    public static int IndexOf<T>(this IEnumerable<T> ie, Func<T, bool> predicate)
    Parameters
    Type Name Description
    IEnumerable<T> ie
    Func<T, bool> predicate
    Returns
    Type Description
    int
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    IsNotNullOrEmpty<T>(IEnumerable<T>)

    Determines whether the collection is valid (not null and contains elements).

    Declaration
    public static bool IsNotNullOrEmpty<T>(this IEnumerable<T> collection)
    Parameters
    Type Name Description
    IEnumerable<T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    IsNullOrEmpty<T>(IEnumerable<T>)

    Determines whether the collection is null or empty.

    Declaration
    public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection)
    Parameters
    Type Name Description
    IEnumerable<T> collection
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    NullifyIfEmpty<T>(List<T>)

    Declaration
    public static List<T> NullifyIfEmpty<T>(this List<T> c)
    Parameters
    Type Name Description
    List<T> c
    Returns
    Type Description
    List<T>
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    RandomOrDefault<T>(IReadOnlyList<T>, Random)

    Declaration
    public static T RandomOrDefault<T>(this IReadOnlyList<T> list, Random rng = null)
    Parameters
    Type Name Description
    IReadOnlyList<T> list
    Random rng
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    SafeAddRange<T>(IList<T>, IEnumerable<T>)

    Declaration
    public static void SafeAddRange<T>(this IList<T> list, IEnumerable<T> values)
    Parameters
    Type Name Description
    IList<T> list
    IEnumerable<T> values
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    SafeAdd<T>(IList<T>, T, bool)

    Adds an item to the list if it is not already present.

    Declaration
    public static void SafeAdd<T>(this IList<T> list, T value, bool replaceIfExists = false)
    Parameters
    Type Name Description
    IList<T> list
    T value
    bool replaceIfExists
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    SafeRemoveAt<T>(IList<T>, int)

    Removes the element at the specified index if the index is valid.

    Declaration
    public static void SafeRemoveAt<T>(this IList<T> list, int idx)
    Parameters
    Type Name Description
    IList<T> list
    int idx
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    SwapElements<T>(IList<T>, int, int)

    Swaps elements in a list at the specified indices.

    Declaration
    public static void SwapElements<T>(this IList<T> list, int idx1, int idx2)
    Parameters
    Type Name Description
    IList<T> list
    int idx1
    int idx2
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    ToArrayOrNull<T>(List<T>)

    Declaration
    public static T[] ToArrayOrNull<T>(this List<T> c)
    Parameters
    Type Name Description
    List<T> c
    Returns
    Type Description
    T[]
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    With<T>(List<T>, params T[])

    Declaration
    public static List<T> With<T>(this List<T> list, params T[] items)
    Parameters
    Type Name Description
    List<T> list
    T[] items
    Returns
    Type Description
    List<T>
    Type Parameters
    Name Description
    T
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation