Search Results for

    Show / Hide Table of Contents

    Class DictionaryExtensions

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

    Methods

    Add<TKey, T>(IDictionary<TKey, object>, TKey, T)

    Adds T instance to the dictionary, so we can store any object.

    Declaration
    public static void Add<TKey, T>(this IDictionary<TKey, object> dictionary, TKey key, T value) where T : class
    Parameters
    Type Name Description
    IDictionary<, ><TKey, object> dictionary
    TKey key
    T value
    Type Parameters
    Name Description
    TKey
    T

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

    Tries to add if the key do not exist, otherwise it will replace its value.

    Declaration
    public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    TKey key
    TValue value

    The value to add or replace

    Returns
    Type Description
    TValue

    The value added/updated

    Type Parameters
    Name Description
    TKey
    TValue

    Filter<TKey, TValue>(IDictionary<TKey, TValue>, Func<TKey, TValue, bool>)

    Filters the dictionary based on a predicate.

    Declaration
    public static IDictionary<TKey, TValue> Filter<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, Func<TKey, TValue, bool> predicate)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    Func<, , ><TKey, TValue, bool> predicate
    Returns
    Type Description
    IDictionary<, ><TKey, TValue>
    Type Parameters
    Name Description
    TKey
    TValue

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

    Finds all keys that have the given value.

    Declaration
    public static IEnumerable<TKey> FindKeysForValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TValue value)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    TValue value
    Returns
    Type Description
    IEnumerable<><TKey>
    Type Parameters
    Name Description
    TKey
    TValue

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

    Tries to get the value by key, if it doesn't exist it will add it.

    Declaration
    public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    TKey key
    TValue value
    Returns
    Type Description
    TValue

    The value

    Type Parameters
    Name Description
    TKey
    TValue

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

    Gets the value associated with the specified key. Returns a default value if the key is not found.

    Declaration
    public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    TKey key

    The key associated with the value

    TValue defaultValue

    The value to returns if key doesn't exist

    Returns
    Type Description
    TValue
    Type Parameters
    Name Description
    TKey
    TValue

    Log<TKey, TValue>(IDictionary<TKey, TValue>, string)

    Declaration
    public static void Log<TKey, TValue>(IDictionary<TKey, TValue> dictionary, string separator = "|")
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    string separator
    Type Parameters
    Name Description
    TKey
    TValue

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

    Tries to replace a value inside the dictionary from the key.

    Declaration
    public static bool ReplaceValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    TKey key
    TValue value
    Returns
    Type Description
    bool

    False if doesn't contain the key

    Type Parameters
    Name Description
    TKey
    TValue

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

    Sorts the dictionary by its keys.

    Declaration
    public static IDictionary<TKey, TValue> SortByKey<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    Returns
    Type Description
    IDictionary<, ><TKey, TValue>
    Type Parameters
    Name Description
    TKey
    TValue

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

    Sorts the dictionary by its values.

    Declaration
    public static IOrderedEnumerable<KeyValuePair<TKey, TValue>> SortByValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
    Parameters
    Type Name Description
    IDictionary<, ><TKey, TValue> dictionary
    Returns
    Type Description
    IOrderedEnumerable<><KeyValuePair<TKey, TValue>>
    Type Parameters
    Name Description
    TKey
    TValue
    In This Article
    Back to top Tetra Creations documentation