예제 #1
0
        /// <summary>
        ///     Remove a key from the list
        /// </summary>
        /// <param name="key">The key</param>
        public async Task RemoveKeyAsync(object key)
        {
            using (await _lock.LockAsync().ConfigureAwait(false))
            {
                var checkKey = new TableKey <T, TKey>((TKey)key, _resolver);

                if (!_keyList.Contains(checkKey))
                {
                    return;
                }

                _keyList.Remove(checkKey);

                _keyMap.Remove((TKey)key);

                IsDirty = true;
            }
        }
예제 #2
0
        /// <summary>
        ///     Add a key to the list
        /// </summary>
        /// <param name="key">The key</param>
        public async Task <int> AddKeyAsync(object key)
        {
            using (await _lock.LockAsync().ConfigureAwait(false))
            {
                var newKey = new TableKey <T, TKey>((TKey)key, _resolver);

                if (!_keyList.Contains(newKey))
                {
                    _keyList.Add(newKey);
                    _keyMap.Add((TKey)key, NextKey++);
                    IsDirty = true;
                }
                else
                {
                    var idx = _keyList.IndexOf(newKey);
                    _keyList[idx].Refresh();
                }
            }

            return(_keyMap[(TKey)key]);
        }