Class ObservableDictionary<TKey, TValue>
An ObservableDictionary
Inheritance
Namespace: Umbraco.Cms.Core.Collections
Assembly: Umbraco.Core.dll
Syntax
public class ObservableDictionary<TKey, TValue> : ObservableCollection<TValue> where TKey : notnull
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the indexing key |
| TValue | The type of elements contained in the BindableCollection |
Remarks
Assumes that the key will not change and is unique for each element in the collection. Collection is not thread-safe, so calls should be made single-threaded.
Constructors
View SourceObservableDictionary(Func<TValue, TKey>, IEqualityComparer<TKey>?)
Create new ObservableDictionary
Declaration
public ObservableDictionary(Func<TValue, TKey> keySelector, IEqualityComparer<TKey>? equalityComparer = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<TValue, TKey> | keySelector | Selector function to create key from value |
| IEqualityComparer<TKey> | equalityComparer | The equality comparer to use when comparing keys, or null to use the default comparer. |
Properties
View SourceIndecies
Declaration
protected Dictionary<TKey, int> Indecies { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<TKey, int> |
this[TKey]
Gets or sets the element with the specified key. If setting a new value, new value must have same key.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | Key of element to replace |
Property Value
| Type | Description |
|---|---|
| TValue |
KeySelector
Declaration
protected Func<TValue, TKey> KeySelector { get; }
Property Value
| Type | Description |
|---|---|
| Func<TValue, TKey> |
Keys
Returns all keys
Declaration
public IEnumerable<TKey> Keys { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<TKey> |
Values
Returns all values
Declaration
public IEnumerable<TValue> Values { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<TValue> |
Methods
View SourceChangeKey(TKey, TKey)
Allows us to change the key of an item
Declaration
public void ChangeKey(TKey currentKey, TKey newKey)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | currentKey | |
| TKey | newKey |
ClearCollectionChangedEvents()
Clears all System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged event handlers
Declaration
public void ClearCollectionChangedEvents()
ClearItems()
Removes all items from the collection.
Declaration
protected override void ClearItems()
ContainsKey(TKey)
Determines whether the read-only dictionary contains an element that has the specified key.
Declaration
public bool ContainsKey(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to locate. |
Returns
| Type | Description |
|---|---|
| bool | true if the read-only dictionary contains an element that has the specified key; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
InsertItem(int, TValue)
Inserts an item into the collection at the specified index.
Declaration
protected override void InsertItem(int index, TValue item)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index at which |
| TValue | item | The object to insert. |
Remove(TKey)
Removes the element with the specified key from the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public bool Remove(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the element to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if the element is successfully removed; otherwise, false. This method also returns false if |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| NotSupportedException | The System.Collections.Generic.IDictionary<TKey, TValue> is read-only. |
RemoveItem(int)
Removes the item at the specified index of the collection.
Declaration
protected override void RemoveItem(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the element to remove. |
Replace(TKey, TValue)
Replaces element at given key with new value. New value must have same key.
Declaration
public bool Replace(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | Key of element to replace |
| TValue | value | New value |
Returns
| Type | Description |
|---|---|
| bool | False if key not found |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException |
ReplaceAll(IEnumerable<TValue>)
Declaration
public void ReplaceAll(IEnumerable<TValue> values)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TValue> | values |
TryGetValue(TKey, out TValue)
Gets the value that is associated with the specified key.
Declaration
public bool TryGetValue(TKey key, out TValue val)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to locate. |
| TValue | val |
Returns
| Type | Description |
|---|---|
| bool | true if the object that implements the System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|