Esempio n. 1
0
 /// <summary>Under normal circumstances if an item's key changes while it is in the collection it will no longer be accessible. This method provides a way to maintain consistent internal state. No CollectionChanged events are raised (since this method does not alter the collection itself).</summary>
 public Task UpdateKeyAsync([NotNull] TItem itemBeingModified, [NotNull] Action actionThatModifiesKey)
 {
     return(RunOnSynchronizationContext(() => {
         BackingDictionary.Remove(GetKeyForItem(itemBeingModified));
         actionThatModifiesKey();
         BackingDictionary.Add(GetKeyForItem(itemBeingModified), itemBeingModified);
     }));
 }
Esempio n. 2
0
        /// <summary>
        ///     <see cref="Dictionary{TKey,TValue}.Remove(TKey)"/>
        /// </summary>
        public Task <bool> RemoveKeyAsync([NotNull] TKey key)
        {
            return(RunOnSynchronizationContext(() => {
                if (TryGetValue(key, out var item))
                {
                    BackingDictionary.Remove(key);
                    OnCollectionRemoved(item);
                    return true;
                }

                return false;
            }));
        }
Esempio n. 3
0
        private void InternalRemoveAll(IEnumerable <TItem> enumerable)
        {
            var removedItems = enumerable.Where(item => BackingDictionary.Remove(GetKeyForItem(item))).ToList();

            OnCollectionRemoved(removedItems);
        }