Class OrderedMultiDictionary<TKey, TValue>.View
The OrderedMultiDictionary<TKey,TValue>.View class is used to look at a subset of the keys and values inside an ordered multi-dictionary. It is returned from the Range, RangeTo, RangeFrom, and Reversed methods.
Inheritance
Implements
Inherited Members
Namespace: Wintellect.PowerCollections
Assembly: CADability.dll
Syntax
[Serializable]
public class View : MultiDictionaryBase<TKey, TValue>, ICollection, IDictionary<TKey, ICollection<TValue>>, ICollection<KeyValuePair<TKey, ICollection<TValue>>>, IEnumerable<KeyValuePair<TKey, ICollection<TValue>>>, IEnumerable
Remarks
Views are dynamic. If the underlying dictionary changes, the view changes in sync. If a change is made to the view, the underlying dictionary changes accordingly.
Typically, this class is used in conjunction with a foreach statement to enumerate the keys and values in a subset of the OrderedMultiDictionary. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Range(from, to)) {
// process pair
}
Properties
| Improve this Doc View SourceCount
Number of keys in this view.
Declaration
public override sealed int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | Number of keys that lie within the bounds the view. |
Overrides
Methods
| Improve this Doc View SourceAdd(TKey, TValue)
Adds the given key-value pair to the underlying dictionary of this view.
If key is not within the range of this view, an
ArgumentException is thrown.
Declaration
public override sealed void Add(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | |
| TValue | value |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException |
|
Clear()
Removes all the keys and values within this view from the underlying OrderedMultiDictionary.
Declaration
public override sealed void Clear()
Overrides
Examples
The following removes all the keys that start with "A" from an OrderedMultiDictionary.
dictionary.Range("A", "B").Clear();
|
Improve this Doc
View Source
Contains(TKey, TValue)
Tests if the key-value pair is present in the part of the dictionary being viewed.
Declaration
public override sealed bool Contains(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | Key to check for. |
| TValue | value | Value to check for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the key-value pair is within this view. |
Overrides
ContainsKey(TKey)
Tests if the key is present in the part of the dictionary being viewed.
Declaration
public override sealed bool ContainsKey(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | Key to check |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the key is within this view. |
Overrides
CountValues(TKey)
Gets the number of values associated with a given key.
Declaration
protected override sealed int CountValues(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to count values of. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of values associated with |
Overrides
EnumerateKeys()
Enumerate all the keys in the dictionary.
Declaration
protected override sealed IEnumerator<TKey> EnumerateKeys()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<TKey> | An IEnumerator<TKey> that enumerates all of the keys in the collection that have at least one value associated with them. |
Overrides
Remove(TKey)
Removes the key (and associated value) from the underlying dictionary of this view. If no key in the view is equal to the passed key, the dictionary and view are unchanged.
Declaration
public override sealed bool Remove(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the key was found and removed. False if the key was not found. |
Overrides
Remove(TKey, TValue)
Removes the key and value from the underlying dictionary of this view. that is equal to the passed in key. If no key in the view is equal to the passed key, or has the given value associated with it, the dictionary and view are unchanged.
Declaration
public override sealed bool Remove(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to remove. |
| TValue | value | The value to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the key-value pair was found and removed. False if the key-value pair was not found. |
Overrides
Reversed()
Creates a new View that has the same keys and values as this, in the reversed order.
Declaration
public OrderedMultiDictionary<TKey, TValue>.View Reversed()
Returns
| Type | Description |
|---|---|
| OrderedMultiDictionary.View<> | A new View that has the reversed order of this view. |
TryEnumerateValuesForKey(TKey, out IEnumerator<TValue>)
Enumerate all of the values associated with a given key. If the key exists and has values associated with it, an enumerator for those
values is returned throught values. If the key does not exist, false is returned.
Declaration
protected override sealed bool TryEnumerateValuesForKey(TKey key, out IEnumerator<TValue> values)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to get values for. |
| System.Collections.Generic.IEnumerator<TValue> | values | If true is returned, this parameter receives an enumerators that enumerates the values associated with that key. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the key exists and has values associated with it. False otherwise. |