Exemple #1
0
    public void Clear()
    {
        lock (_dictionaryLock) dictionary.Clear();
        DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
        {
            Operation = DDictionaryOperation.CLEAR,
            Success   = true
        };

        onChange?.Invoke(this, parametros);
    }
Exemple #2
0
    public void Add(TKey key, TValue value)
    {
        lock (_dictionaryLock) dictionary.Add(key, value);
        DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
        {
            Key       = key,
            Value     = value,
            Operation = DDictionaryOperation.ADD,
            Success   = true
        };

        onChange?.Invoke(this, parametros);
    }
Exemple #3
0
    public void Add(KeyValuePair <TKey, TValue> item)
    {
        lock (_dictionaryLock) dictionary.Add(item);
        DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
        {
            Key       = item.Key,
            Value     = item.Value,
            Operation = DDictionaryOperation.ADD,
            Success   = true
        };

        onChange?.Invoke(this, parametros);
    }
Exemple #4
0
    public TValue this[TKey key]
    {
        get
        {
            lock (_dictionaryLock)
            {
                if (dictionary.ContainsKey(key))
                {
                    return(dictionary[key]);
                }
                else
                {
                    return(defaultValue);
                }
            }
        }

        set
        {
            bool success            = false;
            DDictionaryOperation op = DDictionaryOperation.SET;

            lock (_dictionaryLock)
            {
                if (dictionary.ContainsKey(key))
                {
                    if (!Object.Equals(dictionary[key], value))
                    {
                        dictionary[key] = value;
                        success         = true;
                    }
                }
                else if (!Object.Equals(defaultValue, value))
                {
                    dictionary[key] = value;
                    success         = true;
                    op = DDictionaryOperation.ADD;
                }
            }

            DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
            {
                Key       = key,
                Value     = value,
                Operation = op,
                Success   = success
            };
            onChange?.Invoke(this, parametros);
        }
    }
Exemple #5
0
    public bool Remove(TKey key)
    {
        bool retorno = false;

        lock (_dictionaryLock) retorno = dictionary.Remove(key);
        DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
        {
            Key       = key,
            Operation = DDictionaryOperation.REMOVE,
            Success   = retorno
        };

        onChange?.Invoke(this, parametros);
        return(retorno);
    }
Exemple #6
0
    public bool Remove(KeyValuePair <TKey, TValue> item)
    {
        bool retorno = false;

        lock (_dictionaryLock) retorno = dictionary.Remove(item);
        DDictionaryChangeEventArgs <TKey, TValue> parametros = new DDictionaryChangeEventArgs <TKey, TValue>
        {
            Key       = item.Key,
            Value     = item.Value,
            Operation = DDictionaryOperation.REMOVE,
            Success   = retorno
        };

        onChange?.Invoke(this, parametros);
        return(retorno);
    }