Class ListDictionary<TKey, TValue>
A dictionary of lists.
Implements
Namespace: Sartorius.SAF.Infrastructure
Assembly: Sartorius.SAF.dll
Syntax
public sealed class ListDictionary<TKey, TValue> : IDictionary<TKey, IList<TValue>>, ICollection<KeyValuePair<TKey, IList<TValue>>>, IEnumerable<KeyValuePair<TKey, IList<TValue>>>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| TKey | The key to use for lists. |
| TValue | The type of the value held by lists. |
Properties
View SourceCount
Gets the number of lists in the dictionary.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | Value indicating the values count. |
this[TKey]
Gets or sets the list associated with the given key. The access always succeeds, eventually returning an empty list.
Declaration
public IList<TValue> this[TKey key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the list to access. |
Property Value
| Type | Description |
|---|---|
| IList<TValue> | The list associated with the key. |
Keys
Gets the list of keys in the dictionary.
Declaration
public ICollection<TKey> Keys { get; }
Property Value
| Type | Description |
|---|---|
| ICollection<TKey> | Collection of keys. |
Values
Gets a shallow copy of all values in all lists.
Declaration
public IList<TValue> Values { get; }
Property Value
| Type | Description |
|---|---|
| IList<TValue> | List of values. |
Methods
View SourceAdd(TKey)
If a list does not already exist, it will be created automatically.
Declaration
public void Add(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the list that will hold the value. |
Add(TKey, TValue)
Adds a value to a list with the given key. If a list does not already exist, it will be created automatically.
Declaration
public void Add(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the list that will hold the value. |
| TValue | value | The value to add to the list under the given key. |
Clear()
Removes all entries in the dictionary.
Declaration
public void Clear()
ContainsKey(TKey)
Determines whether the dictionary contains the given key.
Declaration
public bool ContainsKey(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to locate. |
Returns
| Type | Description |
|---|---|
| bool | true if the dictionary contains the given key; otherwise, false. |
ContainsValue(TValue)
Determines whether the dictionary contains the specified value.
Declaration
public bool ContainsValue(TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value to locate. |
Returns
| Type | Description |
|---|---|
| bool | true if the dictionary contains the value in any list; otherwise, false. |
FindAllValues(Predicate<TValue>)
Retrieves all the elements that match the condition defined by the specified predicate.
Declaration
public IEnumerable<TValue> FindAllValues(Predicate<TValue> valueFilter)
Parameters
| Type | Name | Description |
|---|---|---|
| Predicate<TValue> | valueFilter | The filter with the condition to use to filter values. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TValue> | The elements that match the condition defined by the specified predicate. |
FindAllValuesByKey(Predicate<TKey>)
Retrieves the all the elements from the list which have a key that matches the condition defined by the specified predicate.
Declaration
public IEnumerable<TValue> FindAllValuesByKey(Predicate<TKey> keyFilter)
Parameters
| Type | Name | Description |
|---|---|---|
| Predicate<TKey> | keyFilter | The filter with the condition to use to filter lists by their key. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TValue> | The elements that have a key that matches the condition defined by the specified predicate. |
Remove(TKey)
Removes a list by key.
Declaration
public bool Remove(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the list to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if the element was removed. |
Remove(TKey, TValue)
Removes a value from the list with the given key.
Declaration
public void Remove(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the list where the value exists. |
| TValue | value | The value to remove. |
Remove(TValue)
Removes a value from all lists where it may be found.
Declaration
public void Remove(TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value to remove. |