Interface IMultiDictionary<TKey, TValue>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic collection of (key, value-range) pairs.
public interface IMultiDictionary<TKey, TValue> : IDictionary<TKey, IReadOnlyList<TValue>>, ICollection<KeyValuePair<TKey, IReadOnlyList<TValue>>>, IReadOnlyMultiDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, IReadOnlyList<TValue>>, IReadOnlyCollection<KeyValuePair<TKey, IReadOnlyList<TValue>>>, IEnumerable<KeyValuePair<TKey, IReadOnlyList<TValue>>>, ILookup<TKey, TValue>, IEnumerable<IGrouping<TKey, TValue>>, IEnumerable where TKey : notnull
Type Parameters
TKey
Key type.
TValue
Value type.
- Inherited Members
- Extension Methods
Properties
Count
Gets the number of elements contained in the ICollection<T>.
int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
this[TKey]
Gets or sets the element with the specified key.
IReadOnlyList<TValue> this[TKey key] { get; set; }
Parameters
key
TKeyThe key of the element to get or set.
Property Value
- IReadOnlyList<TValue>
The element with the specified key.
Exceptions
- ArgumentNullException
key
is null.- KeyNotFoundException
The property is retrieved and
key
is not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
IReadOnlyCollection<TKey> Keys { get; }
Property Value
- IReadOnlyCollection<TKey>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
IReadOnlyCollection<IReadOnlyList<TValue>> Values { get; }
Property Value
- IReadOnlyCollection<IReadOnlyList<TValue>>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(TKey, TValue)
Adds a new entry to this dictionary.
void Add(TKey key, TValue value)
Parameters
key
TKeyEntry's key.
value
TValueEntry's value.
AddRange(TKey, IEnumerable<TValue>)
Adds a range of entries associated with the provided key
to this dictionary.
void AddRange(TKey key, IEnumerable<TValue> values)
Parameters
key
TKeyEntry's key.
values
IEnumerable<TValue>Range of values.
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
[Pure]
bool ContainsKey(TKey key)
Parameters
key
TKeyThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
key
is null.
Remove(TKey)
Removes all elements associated with the specified key
.
IReadOnlyList<TValue> Remove(TKey key)
Parameters
key
TKeyKey to remove.
Returns
- IReadOnlyList<TValue>
All removed elements associated with the specified
key
.
Remove(TKey, TValue)
Attempts to remove a specific element associated with the specified key
.
bool Remove(TKey key, TValue value)
Parameters
key
TKeyEntry's key.
value
TValueValue to remove.
Returns
- bool
true when key exists and value has been removed, otherwise false.
RemoveAll(TKey, Predicate<TValue>)
Attempts to remove all elements associated with the specified key
that pass the provided predicate
.
int RemoveAll(TKey key, Predicate<TValue> predicate)
Parameters
key
TKeyEntry's key.
predicate
Predicate<TValue>Delegate that defines which elements to remove.
Returns
- int
Number of removed elements.
RemoveAt(TKey, int)
Attempts to remove an element associated with the specified key
at the provided index
.
bool RemoveAt(TKey key, int index)
Parameters
key
TKeyEntry's key.
index
int0-based position of an element to remove.
Returns
- bool
true when an element has been removed, otherwise false.
Exceptions
- ArgumentOutOfRangeException
When
index
is less than 0 or greater than or equal to the number of elements associated with the specifiedkey
.
RemoveRange(TKey, int, int)
Attempts to remove a range of elements associated with the specified key
.
bool RemoveRange(TKey key, int index, int count)
Parameters
key
TKeyEntry's key.
index
int0-based position of a first element to remove.
count
intTotal number of elements to remove, starting from the provided
key
.
Returns
- bool
true when a range of elements has been removed, otherwise false.
Exceptions
- ArgumentOutOfRangeException
When
index
orcount
is less than 0.- ArgumentException
When
index
andcount
do not denote a valid range of elements.
SetRange(TKey, IEnumerable<TValue>)
Sets a range of entries associated with the provided key
in this dictionary.
void SetRange(TKey key, IEnumerable<TValue> values)
Parameters
key
TKeyEntry's key.
values
IEnumerable<TValue>Range of values.
TryGetValue(TKey, out IReadOnlyList<TValue>)
Gets the value associated with the specified key.
bool TryGetValue(TKey key, out IReadOnlyList<TValue> result)
Parameters
key
TKeyThe key whose value to get.
result
IReadOnlyList<TValue>
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Exceptions
- ArgumentNullException
key
is null.