Table of Contents

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

TKey

The type of keys in the dictionary.

TValue

The 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>
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

dictionary IDictionary<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

dictionary IDictionary<TKey, TValue>

The dictionary whose elements are copied to the new bindable dictionary.

comparer IEqualityComparer<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

collection IEnumerable<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

collection IEnumerable<KeyValuePair<TKey, TValue>>

The collection whose elements are copied to the new bindable dictionary.

comparer IEqualityComparer<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

comparer IEqualityComparer<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

capacity int

The 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

capacity int

The initial number of elements that the dictionary can contain.

comparer IEqualityComparer<TKey>

The equality comparer to use when comparing keys.

Properties

Count

public int Count { get; }

Property Value

int

IsFixedSize

public bool IsFixedSize { get; }

Property Value

bool

IsReadOnly

public bool IsReadOnly { get; }

Property Value

bool

IsSynchronized

public bool IsSynchronized { get; }

Property Value

bool

this[object]

public object this[object key] { get; set; }

Parameters

key object

Property Value

object

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

key TKey

The 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

object

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

item KeyValuePair<TKey, TValue>

Add(object, object)

public void Add(object key, object value)

Parameters

key object
value object

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

key TKey

The key of the element to add.

value TValue

The 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

item KeyValuePair<TKey, TValue>

Returns

bool

Contains(object)

public bool Contains(object key)

Parameters

key object

Returns

bool

ContainsKey(TKey)

public bool ContainsKey(TKey key)

Parameters

key TKey

Returns

bool

CopyTo(Array, int)

public void CopyTo(Array array, int index)

Parameters

array Array
index int

CopyTo(KeyValuePair<TKey, TValue>[], int)

public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)

Parameters

array KeyValuePair<TKey, TValue>[]
arrayIndex int

GetEnumerator()

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<TKey, TValue>>

GetObjectData(SerializationInfo, StreamingContext)

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo
context StreamingContext

OnDeserialization(object)

public void OnDeserialization(object sender)

Parameters

sender object

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

item KeyValuePair<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

key object

Remove(TKey)

Removes the element with the specified key from the dictionary and raises the OnElementRemove event.

public bool Remove(TKey key)

Parameters

key TKey

The 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

key TKey
value TValue

Returns

bool

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>