/// <summary> /// Gets or sets the <see cref="dynamic"/> with the specified key. /// </summary> /// <value> /// The <see cref="dynamic"/>. /// </value> /// <param name="key">The key.</param> /// <returns></returns> public dynamic this[string key] { get { if (!_dictionary.ContainsKey(key)) { _dictionary[key] = new DynamicListValue(); } dynamic obj = _dictionary[key]; return(obj); } set { if (_dictionary.ContainsKey(key)) { var val = _dictionary[key]; _dictionary[key] = new DynamicListValue(value) { UseDistinct = UseDistinct }; _dictionary[key].OnDynamicListValueChanged += OnValueChanged; if (val != value) { RaiseEvent(DynamicDictionaryChangedType.ChangedValue, key, value); } } else { Add(key, value); } } }
private void RaiseEvent(DynamicDictionaryChangedType type, string key, DynamicListValue value, DynamicListValue oldValue = null) { OnChange?.Invoke(this, new DynamicDictionaryChangedArgs { EventType = type, Key = key, OldValue = oldValue, Value = value }); SaveAsync((DynamicDictionarySaveMotive)type); }
/// <summary> /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> /// <returns> /// true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />. /// </returns> public bool Remove(KeyValuePair <string, object> item) { DynamicListValue value = new DynamicListValue(item.Value); if (item.Value is DynamicListValue) { value = item.Value as DynamicListValue; } var pair = new KeyValuePair <string, DynamicListValue>(item.Key, value); if (_dictionary.Remove(pair)) { RaiseEvent(DynamicDictionaryChangedType.RemovedValue, pair.Key, pair.Value); return(true); } return(false); }