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
Gets the dictionary mapping keys to their indices in the collection.
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
Gets the function used to extract a key from a value.
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()
Declaration
protected override void ClearItems()
ContainsKey(TKey)
Declaration
public bool ContainsKey(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key |
Returns
| Type | Description |
|---|---|
| bool |
InsertItem(int, TValue)
Declaration
protected override void InsertItem(int index, TValue item)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | |
| TValue | item |
Remove(TKey)
Removes the element with the specified key from the dictionary.
Declaration
public bool Remove(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the element to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
RemoveItem(int)
Declaration
protected override void RemoveItem(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index |
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>)
Replaces all elements in the dictionary with the specified values.
Declaration
public void ReplaceAll(IEnumerable<TValue> values)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TValue> | values | The values to replace the current elements with. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
TryGetValue(TKey, out TValue)
Declaration
public bool TryGetValue(TKey key, out TValue val)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | |
| TValue | val |
Returns
| Type | Description |
|---|---|
| bool |