Class BindableDictionary<TKey, TValue>
- Namespace
- Bindables
- Assembly
- Bindables.dll
A bindable dictionary implementation that raises events when the dictionary or its elements are modified. Supports change notifications at both the dictionary level and individual element level.
[Serializable]
public class BindableDictionary<TKey, TValue> : Bindable<Dictionary<TKey, TValue>>, IBindWritable<Dictionary<TKey, TValue>>, IBindWritable, IBindableDictionary<TKey, TValue>, IBindable<Dictionary<TKey, TValue>>, IBindable, IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable, IDeserializationCallback where TKey : notnull
Type Parameters
TKeyThe type of keys in the dictionary.
TValueThe type of values in the dictionary.
- Inheritance
-
Bindable<Dictionary<TKey, TValue>>BindableDictionary<TKey, TValue>
- Implements
-
IBindWritable<Dictionary<TKey, TValue>>IBindableDictionary<TKey, TValue>IBindable<Dictionary<TKey, TValue>>IDictionary<TKey, TValue>ICollection<KeyValuePair<TKey, TValue>>IReadOnlyDictionary<TKey, TValue>IReadOnlyCollection<KeyValuePair<TKey, TValue>>IEnumerable<KeyValuePair<TKey, TValue>>
- Inherited Members
- Extension Methods
Constructors
BindableDictionary()
Initializes a new instance of the BindableDictionary<TKey, TValue> class that is empty.
public BindableDictionary()
BindableDictionary(IDictionary<TKey, TValue>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that contains elements copied from the specified dictionary.
public BindableDictionary(IDictionary<TKey, TValue> dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>The dictionary whose elements are copied to the new bindable dictionary.
BindableDictionary(IDictionary<TKey, TValue>, IEqualityComparer<TKey>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that contains elements copied from the specified dictionary and uses the specified comparer.
public BindableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer)
Parameters
dictionaryIDictionary<TKey, TValue>The dictionary whose elements are copied to the new bindable dictionary.
comparerIEqualityComparer<TKey>The equality comparer to use when comparing keys.
BindableDictionary(IEnumerable<KeyValuePair<TKey, TValue>>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that contains elements copied from the specified collection.
public BindableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection)
Parameters
collectionIEnumerable<KeyValuePair<TKey, TValue>>The collection whose elements are copied to the new bindable dictionary.
BindableDictionary(IEnumerable<KeyValuePair<TKey, TValue>>, IEqualityComparer<TKey>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that contains elements copied from the specified collection and uses the specified comparer.
public BindableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
Parameters
collectionIEnumerable<KeyValuePair<TKey, TValue>>The collection whose elements are copied to the new bindable dictionary.
comparerIEqualityComparer<TKey>The equality comparer to use when comparing keys.
BindableDictionary(IEqualityComparer<TKey>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that uses the specified comparer.
public BindableDictionary(IEqualityComparer<TKey> comparer)
Parameters
comparerIEqualityComparer<TKey>The equality comparer to use when comparing keys.
BindableDictionary(int)
Initializes a new instance of the BindableDictionary<TKey, TValue> class that is empty and has the specified initial capacity.
public BindableDictionary(int capacity)
Parameters
capacityintThe initial number of elements that the dictionary can contain.
BindableDictionary(int, IEqualityComparer<TKey>)
Initializes a new instance of the BindableDictionary<TKey, TValue> class with the specified capacity and comparer.
public BindableDictionary(int capacity, IEqualityComparer<TKey> comparer)
Parameters
capacityintThe initial number of elements that the dictionary can contain.
comparerIEqualityComparer<TKey>The equality comparer to use when comparing keys.
Properties
Count
public int Count { get; }
Property Value
IsFixedSize
public bool IsFixedSize { get; }
Property Value
IsReadOnly
public bool IsReadOnly { get; }
Property Value
IsSynchronized
public bool IsSynchronized { get; }
Property Value
this[object]
public object this[object key] { get; set; }
Parameters
keyobject
Property Value
this[TKey]
Gets or sets the value associated with the specified key. Setting a value for a new key raises OnElementAdd. Setting a different value for an existing key raises OnElementChange.
public TValue this[TKey key] { get; set; }
Parameters
keyTKeyThe key of the value to get or set.
Property Value
- TValue
The value associated with the specified key.
Keys
public ICollection<TKey> Keys { get; }
Property Value
- ICollection<TKey>
SyncRoot
public object SyncRoot { get; }
Property Value
Value
Gets or sets the underlying dictionary value. Setting this property replaces the entire dictionary and raises the Changed event.
public Dictionary<TKey, TValue> Value { get; set; }
Property Value
- Dictionary<TKey, TValue>
Values
public ICollection<TValue> Values { get; }
Property Value
- ICollection<TValue>
Methods
Add(KeyValuePair<TKey, TValue>)
public void Add(KeyValuePair<TKey, TValue> item)
Parameters
itemKeyValuePair<TKey, TValue>
Add(object, object)
public void Add(object key, object value)
Parameters
Add(TKey, TValue)
Adds the specified key and value to the dictionary and raises the OnElementAdd event.
public void Add(TKey key, TValue value)
Parameters
keyTKeyThe key of the element to add.
valueTValueThe value of the element to add.
Clear()
Removes all elements from the dictionary and raises the Changed event if the dictionary was not empty.
public void Clear()
Contains(KeyValuePair<TKey, TValue>)
public bool Contains(KeyValuePair<TKey, TValue> item)
Parameters
itemKeyValuePair<TKey, TValue>
Returns
Contains(object)
public bool Contains(object key)
Parameters
keyobject
Returns
ContainsKey(TKey)
public bool ContainsKey(TKey key)
Parameters
keyTKey
Returns
CopyTo(Array, int)
public void CopyTo(Array array, int index)
Parameters
CopyTo(KeyValuePair<TKey, TValue>[], int)
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<TKey, TValue>[]arrayIndexint
GetEnumerator()
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<TKey, TValue>>
GetObjectData(SerializationInfo, StreamingContext)
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfocontextStreamingContext
OnDeserialization(object)
public void OnDeserialization(object sender)
Parameters
senderobject
Remove(KeyValuePair<TKey, TValue>)
Removes the element with the specified item from the dictionary and raises the OnElementRemove event.
public bool Remove(KeyValuePair<TKey, TValue> item)
Parameters
itemKeyValuePair<TKey, TValue>The item to remove.
Returns
- bool
true if the element was successfully removed; otherwise, false.
Remove(object)
public void Remove(object key)
Parameters
keyobject
Remove(TKey)
Removes the element with the specified key from the dictionary and raises the OnElementRemove event.
public bool Remove(TKey key)
Parameters
keyTKeyThe key of the element to remove.
Returns
- bool
true if the element was successfully removed; otherwise, false.
TryGetValue(TKey, out TValue)
public bool TryGetValue(TKey key, out TValue value)
Parameters
keyTKeyvalueTValue
Returns
Events
OnElementAdd
Occurs when an element is added to the dictionary.
public event Action<TKey, TValue> OnElementAdd
Event Type
- Action<TKey, TValue>
OnElementChange
Occurs when an element's value is changed in the dictionary.
public event Action<TKey, TValue, TValue> OnElementChange
Event Type
- Action<TKey, TValue, TValue>
OnElementRemove
Occurs when an element is removed from the dictionary.
public event Action<TKey, TValue> OnElementRemove
Event Type
- Action<TKey, TValue>