private bool HandledEvent(AsyncCollectionRequest <KeyValuePair <TKey, TValue> > request)
        {
            var changesMade = false;

            if (request.EventType == AsyncCollectionEventType.Clear)
            {
                changesMade = true;
                _trustedSource.Clear();
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                return(changesMade);
            }

            switch (request.EventType)
            {
            case (AsyncCollectionEventType.Remove):
                if (_trustedSource.ContainsKey((TKey)request.Data))
                {
                    changesMade = true;
                    _trustedSource.Remove((TKey)request.Data);
                }
                break;

            case (AsyncCollectionEventType.TryUpdate):
            case (AsyncCollectionEventType.TryAdd):
            {
                var kvp = (KeyValuePair <TKey, TValue>)request.Data;
                if (!_trustedSource.ContainsKey(kvp.Key))
                {
                    if (AsyncCollectionEventType.TryAdd == request.EventType)
                    {
                        changesMade = true;
                        _trustedSource.Add(kvp.Key, kvp.Value);
                    }
                }
                else
                {
                    changesMade = true;
                    if (request.TryFunc == null)
                    {
                        _trustedSource[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        var currentValue  = _trustedSource[kvp.Key];
                        var selectedValue = request.TryFunc(new KeyValuePair <TKey, TValue>(kvp.Key, currentValue), kvp);
                        _trustedSource[kvp.Key] = selectedValue.Value;
                    }
                }
            }
            break;
            }
            return(changesMade);
        }
        private bool HandledEvent(AsyncCollectionRequest <T> request)
        {
            var changesMade = false;

            if (request.EventType == AsyncCollectionEventType.Clear)
            {
                changesMade = true;
                _trustedSource.Clear();
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                return(changesMade);
            }

            switch (request.EventType)
            {
            case (AsyncCollectionEventType.Remove):
                if (request.Index >= 0 && _trustedSource.Count > request.Index)
                {
                    changesMade = true;
                    _trustedSource.RemoveAt(request.Index);
                }
                else if (request.Data != null)
                {
                    changesMade = true;
                    _trustedSource.Remove((T)request.Data);
                }
                break;

            case (AsyncCollectionEventType.Add):
                changesMade = true;
                _trustedSource.Add((T)request.Data);
                break;

            case (AsyncCollectionEventType.TryUpdate):
                if (request.Index >= 0 && _trustedSource.Count > request.Index)
                {
                    changesMade = true;
                    _trustedSource[request.Index] = (T)request.Data;
                }

                break;

            case (AsyncCollectionEventType.TryInsert):
                if (request.Index >= 0 && _trustedSource.Count > request.Index)
                {
                    changesMade = true;
                    _trustedSource.Insert(request.Index, (T)request.Data);
                }

                break;
            }
            return(changesMade);
        }