Class ObservableDictionary<TKey, TValue>
An implementation of IDictionary<TKey><TValue> which fires System.Collections.Specialized.INotifyCollectionChanged
and System.ComponentModel.INotifyPropertyChanged when required. This allows the dictionary to be used as
a data source for WPF user controls implementing data-binding.
Implements
Inherited Members
Namespace: Sdl.FileTypeSupport.Framework.Core.Settings
Assembly: Sdl.FileTypeSupport.Framework.Core.Settings.dll
Syntax
public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key used in the dictionary. |
| TValue | The type of the value used in the dictionary. |
Constructors
ObservableDictionary()
Default constructor creating a new dictionary with the default capacity.
Declaration
public ObservableDictionary()
ObservableDictionary(Int32)
Constructor creating a new dictionary with the specified capacity.
Declaration
public ObservableDictionary(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | size | The initial capacity of the dictionary. |
ObservableDictionary(SerializationInfo, StreamingContext)
Creates a new dictionary based on the serialization information provided.
Declaration
protected ObservableDictionary(SerializationInfo info, StreamingContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Runtime.Serialization.SerializationInfo | info | |
| System.Runtime.Serialization.StreamingContext | context |
Properties
Count
The number of elements contained in the dictionary.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
IsReadOnly
Determines whether the dictionary is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Item[TKey]
Retrieves the dictionary element value at the specified key.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the element to get. |
Property Value
| Type | Description |
|---|---|
| TValue | The value of the element at the specified key. |
Keys
A collection of all element keys contained in the dictionary.
Declaration
public ICollection<TKey> Keys { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.ICollection<TKey> |
Values
A collection of all element values contained in the dictionary.
Declaration
public ICollection<TValue> Values { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.ICollection<TValue> |
Methods
Add(TKey, TValue)
Adds an element with the key and value to the dictionary or updates the value if the key already exists.
Declaration
public void Add(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The object to use as the key for the element. |
| TValue | value | The object to use as the value for the element. |
Add(KeyValuePair<TKey, TValue>)
Adds a new element to the dictionary.
Declaration
public void Add(KeyValuePair<TKey, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue> | item | The element to add to the dictionary. |
Clear()
Removes all elements from the dictionary.
Declaration
public void Clear()
ClearDictionaryItemSettings(ISettingsGroup, String)
Removes all saved items belonging to this dictionary from the stored settings group. This is called from SaveToSettingsGroup(ISettingsGroup, String) to make sure that the settings being updated are all saved cleanly.
Declaration
protected virtual void ClearDictionaryItemSettings(ISettingsGroup settingsGroup, string listSettingId)
Parameters
| Type | Name | Description |
|---|---|---|
| ISettingsGroup | settingsGroup | The settings group to remove the settings from. |
| System.String | listSettingId | The ID of the setting to remove. |
Contains(KeyValuePair<TKey, TValue>)
Determines whether the dictionary contains the specified item.
Declaration
public bool Contains(KeyValuePair<TKey, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue> | item | The item to look for. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ContainsKey(TKey)
Determines whether the dictionary contains an element with the specified key.
Declaration
public bool ContainsKey(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to search the dictionary for. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
CopyTo(KeyValuePair<TKey, TValue>[], Int32)
Copies the dictionary elements into the provided array, starting from the specified index in the array.
Declaration
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue>[] | array | The index to copy the dictionary elements in to. |
| System.Int32 | arrayIndex | The index in the array to start copying from. |
GetDictionaryItemFromSettings<T>(ISettingsGroup, String, out Boolean)
Gets the setting for the dictionary item from the settings group and populates it.
Declaration
protected virtual T GetDictionaryItemFromSettings<T>(ISettingsGroup settingsGroup, string listItemSetting, out bool found)
Parameters
| Type | Name | Description |
|---|---|---|
| ISettingsGroup | settingsGroup | The settings group containing the dictionary item settings. |
| System.String | listItemSetting | The setting ID to use to retrieve the setting. |
| System.Boolean | found | A flag which reports if the setting was found or not. |
Returns
| Type | Description |
|---|---|
| T | The populated dictionary item. |
Type Parameters
| Name | Description |
|---|---|
| T |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
GetObjectData(SerializationInfo, StreamingContext)
Populates serialization information with the elements in the dictionary.
Declaration
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Runtime.Serialization.SerializationInfo | info | |
| System.Runtime.Serialization.StreamingContext | context |
PopulateFromSettingsGroup(ISettingsGroup, String)
Restores the dictionary from the settings group and populates itself using the setting ID as its base.
Declaration
public virtual void PopulateFromSettingsGroup(ISettingsGroup settingsGroup, string listSettingId)
Parameters
| Type | Name | Description |
|---|---|---|
| ISettingsGroup | settingsGroup | The settings group to load from. |
| System.String | listSettingId | The setting ID to use as a base when populating the dictionary. |
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 |
|---|---|
| System.Boolean |
|
Remove(KeyValuePair<TKey, TValue>)
Removes the specified item from the dictionary.
Declaration
public bool Remove(KeyValuePair<TKey, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue> | item | The item to remove from the dictionary. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
SaveToSettingsGroup(ISettingsGroup, String)
Saves this dictionary to the settings group using the setting ID as a base.
Declaration
public virtual void SaveToSettingsGroup(ISettingsGroup settingsGroup, string listSettingId)
Parameters
| Type | Name | Description |
|---|---|---|
| ISettingsGroup | settingsGroup | The settings group to save to. |
| System.String | listSettingId | The setting ID to use as a base when saving the dictionary. |
TryGetValue(TKey, out TValue)
Gets the value of the element with the specified key if it exists.
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key of the element to get. |
| TValue | value | The value of the element at the specified key. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Events
CollectionChanged
Event that is fired whenever the contents of the collection are changed.
Declaration
public event NotifyCollectionChangedEventHandler CollectionChanged
Event Type
| Type | Description |
|---|---|
| System.Collections.Specialized.NotifyCollectionChangedEventHandler |
PropertyChanged
Event that is fired whenever the value of a property of the collection is changed.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
| Type | Description |
|---|---|
| System.ComponentModel.PropertyChangedEventHandler |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |