DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.7.0" />

 Dictionary

public static class Dictionary
Represents various extensions for types Dictionary<T, U> and IDictionary<T, U>.
public static class Indexer<TKey, TValue>

Provides strongly-typed access to dictionary indexer.

public static ReadOnlyDictionaryView<TKey, TValue, TResult> ConvertValues<TKey, TValue, TResult>(this IReadOnlyDictionary<TKey, TValue> dictionary, Converter<TValue, TResult> mapper)

Applies lazy conversion for each dictionary value.

public static IReadOnlyDictionary<TKey, TValue> Empty<TKey, TValue>()

Gets empty read-only dictionary.

public static void ForEach<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, Action<TKey, TValue> action)

Applies specific action to each dictionary.

public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)

Adds a key-value pair to the dictionary if the key does not exist.

public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)

Adds a key-value pair to the dictionary if the key does not exist.

public static TValue GetOrAdd<TKey, TValue, TFactory>(this Dictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory) where TFactory : struct, ISupplier<TKey, TValue>

Generates a value and adds the key-value pair to the dictionary if the key does not exist.

public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory)

Generates a value and adds the key-value pair to the dictionary if the key does not exist.

public static TValue GetOrInvoke<TKey, TValue, TSupplier>(this IDictionary<TKey, TValue> dictionary, TKey key, TSupplier defaultValue) where TSupplier : struct, ISupplier<TValue>

Gets dictionary value by key if it exists or invoke defaultValue and return its result as a default value.

public static TValue GetOrInvoke<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> defaultValue)

Gets dictionary value by key if it exists or invoke defaultValue and return its result as a default value.

public static Func<TKey, TValue> IndexerGetter<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary)

Returns get_Item as delegate attached to the dictionary instance.

public static Func<TKey, TValue> IndexerGetter<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)

Returns get_Item as delegate attached to the dictionary instance.

public static Action<TKey, TValue> IndexerSetter<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)

Returns set_Item as delegate attached to the dictionary instance.

public static Func<IEnumerable<TKey>> KeysGetter<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary)

Returns Keys as delegate attached to the dictionary instance.

public static Func<ICollection<TKey>> KeysGetter<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)

Returns Keys as delegate attached to the dictionary instance.

public static Optional<TValue> TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)

Gets the value associated with the specified key.

public static Optional<TValue> TryGetValue<TKey, TValue>(IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)

Gets the value associated with the specified key.

public static Optional<TValue> TryRemove<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)

Removes the value with the specified key and return the removed value.

public static Func<IEnumerable<TValue>> ValuesGetter<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary)

Returns Values as delegate attached to the dictionary instance.

public static Func<ICollection<TValue>> ValuesGetter<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)

Returns Values as delegate attached to the dictionary instance.