Table of Contents

Class CollectionDictionary<T, U>

Namespace
The.Utility
Assembly
Instagile.dll

A dictionary that maps keys to collections of values, providing convenient methods for managing multi-value associations.

public class CollectionDictionary<T, U> : Dictionary<T, List<U>>, IDictionary<T, List<U>>, ICollection<KeyValuePair<T, List<U>>>, IReadOnlyDictionary<T, List<U>>, IReadOnlyCollection<KeyValuePair<T, List<U>>>, IEnumerable<KeyValuePair<T, List<U>>>, IDictionary, ICollection, IEnumerable, IDeserializationCallback, ISerializable where T : notnull

Type Parameters

T

The type of keys in the dictionary.

U

The type of values in the collections.

Inheritance
CollectionDictionary<T, U>
Implements
Inherited Members

Constructors

CollectionDictionary(IEqualityComparer<T>?)

A dictionary that maps keys to collections of values, providing convenient methods for managing multi-value associations.

public CollectionDictionary(IEqualityComparer<T>? keyComparer = null)

Parameters

keyComparer IEqualityComparer<T>

Properties

this[T]

Gets the collection of values associated with the specified key as a read-only list. If the key does not exist, creates a new empty collection.

public IReadOnlyList<U> this[T key] { get; }

Parameters

key T

The key of the collection to get.

Property Value

IReadOnlyList<U>

A read-only list of values associated with the key.

Methods

Add(T, U)

Adds a value to the collection associated with the specified key. If the key does not exist, creates a new collection for that key.

public void Add(T key, U value)

Parameters

key T

The key of the collection to add the value to.

value U

The value to add to the collection.

Merge(ILookup<T, U>)

Merges all key-value pairs from a lookup into this collection dictionary.

public void Merge(ILookup<T, U> input)

Parameters

input ILookup<T, U>

The lookup to merge into this collection dictionary.

Remove(T, U)

Removes a specific value from the collection associated with the specified key.

public bool Remove(T key, U value)

Parameters

key T

The key of the collection to remove the value from.

value U

The value to remove from the collection.

Returns

bool

true if the value was found and removed; otherwise, false.

RemoveAll(T)

Removes all values from the collection associated with the specified key and returns them. The key itself remains in the dictionary with an empty collection.

public IEnumerable<U> RemoveAll(T key)

Parameters

key T

The key of the collection to remove all values from.

Returns

IEnumerable<U>

An enumerable containing all the values that were removed, or an empty collection if the key was not found.

ToLookup()

Converts this collection dictionary to an ILookup<TKey, TElement>.

public CollectionDictionary<T, U>.Lookup ToLookup()

Returns

CollectionDictionary<T, U>.Lookup

A lookup that provides a read-only view of this collection dictionary.