diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableCollection.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableCollection.cs index 8847111..4ce37a8 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableCollection.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableCollection.cs @@ -114,7 +114,7 @@ public virtual void AddRange(IList items) => DoReadWriteNotify( () => ImmutableList.Count, (index) => ImmutableList.AddRange(items), - (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items, index) + (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items as IList ?? items.ToList(), index) ); /// @@ -124,7 +124,7 @@ public virtual void AddRange(IList items) => public virtual void InsertRange(int index, IList items) => DoWriteNotify( () => ImmutableList.InsertRange(index, items), - () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items, index) + () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items as IList ?? items.ToList(), index) ); /// @@ -134,21 +134,21 @@ public void RemoveRange(int index, int count) => DoReadWriteNotify( () => ImmutableList.GetRange(index, count), (items) => ImmutableList.RemoveRange(index, count), - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, index) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items, index) ); public void RemoveRange(IList items) => DoWriteNotify( () => ImmutableList.RemoveRange(items), - () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items) + () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items as IList ?? items.ToList()) ); public virtual void Reset(IList items) => DoReadWriteNotify( () => ImmutableList.ToArray(), (oldItems) => ImmutableList.Empty.AddRange(items), - (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)oldItems, 0), - (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items, 0) + (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldItems, 0), + (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items as IList ?? items.ToList(), 0) ); public T[] ToArray() => ImmutableList.ToArray(); @@ -258,7 +258,7 @@ public void Clear() => DoReadWriteNotify( () => ImmutableList.ToArray(), (items) => ImmutableList.Clear(), - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, 0) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items, 0) ); public bool Contains(T item) => ImmutableList.Contains(item); diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableDictionary.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableDictionary.cs index c405122..1a64e1e 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableDictionary.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableDictionary.cs @@ -68,16 +68,10 @@ public virtual void Add(KeyValuePair pair) /// public virtual void AddRange(IEnumerable> pairs) { - // Convert to a list off the bat, as this is used multiple times and is required to be - // an IList for NotifyCollectionChangedEventArgs - if (!(pairs is IList> pairsList)) - { - pairsList = pairs.ToList(); - } DoReadWriteNotify( () => _internalCollection.Count, - (index) => _internalCollection.AddRange(pairsList), - (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)pairsList, index) + (index) => _internalCollection.AddRange(pairs), + (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, pairs as IList ?? pairs.ToList(), index) ); } @@ -250,7 +244,7 @@ public IList> RemoveRange(int index, int count) (items) => { localRemovedItems = items; - return new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, index); + return new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items as IList ?? items.ToList(), index); } ); return localRemovedItems; @@ -271,7 +265,7 @@ public void RemoveRange(IEnumerable keys) // remove the keys from the dictionary, remove the range from the list (items) => _internalCollection.RemoveRange(keysList), // Notify which items were removed - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items as IList ?? items.ToList()) ); } @@ -414,7 +408,7 @@ public void Clear() // remove the keys from the dictionary, remove the range from the list (items) => ImmutableDictionaryListPair.Empty, // Notify which items were removed - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, 0) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items, 0) ); } diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableHashSet.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableHashSet.cs index d165051..3b0703a 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableHashSet.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableHashSet.cs @@ -63,17 +63,10 @@ public bool Add(T value) /// public void AddRange(IEnumerable values) { - // Convert to a list off the bat, as this is used multiple times and is required to be - // an IList for NotifyCollectionChangedEventArgs - if (!(values is IList valuesList)) - { - valuesList = values.ToList(); - } - DoReadWriteNotify( () => _internalCollection.Count, - (index) => ((ImmutableHashSet)_internalCollection).AddRange(valuesList), - (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)valuesList, index) + (index) => ((ImmutableHashSet)_internalCollection).AddRange(values), + (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, values as IList ?? values.ToList(), index) ); } @@ -96,23 +89,16 @@ public bool Remove(T value) public void RemoveRange(IEnumerable values) { - // Convert to a list off the bat, as this is used multiple times and is required to be - // an IList for NotifyCollectionChangedEventArgs - if (!(values is IList valuesList)) - { - valuesList = values.ToList(); - } - DoWriteNotify( - () => ((ImmutableHashSet)_internalCollection).RemoveRange(valuesList), - () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)valuesList) + () => ((ImmutableHashSet)_internalCollection).RemoveRange(values), + () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, values as IList ?? values.ToList()) ); } /// /// This is the view of the colleciton that you should be binding to with your ListView/GridView control. /// - public override IList CollectionView => ((IEnumerable)_internalCollection).ToList(); + public override IList CollectionView => _internalCollection.ToList(); public override int Count => _internalCollection.Count; @@ -148,7 +134,7 @@ public void Clear() // remove the keys from the dictionary, remove the range from the list (items) => ImmutableHashSet.Empty, // Notify which items were removed - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, 0) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items, 0) ); } diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedCollection.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedCollection.cs index dfcab39..ca22e68 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedCollection.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedCollection.cs @@ -55,7 +55,7 @@ public override void AddRange(IList items) DoReadWriteNotify( () => 0, getIndicesAndInsert, - (nothing) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items.ToList()) + (nothing) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items as IList ?? items.ToList()) ); } @@ -65,8 +65,8 @@ public override void Reset(IList items) => // Should be quicker than sorting 1 by 1 on insert. () => ImmutableList.ToArray(), (oldItems) => ImmutableList.Empty.AddRange(items.OrderBy(x => x, _sorter).ToList()), - (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)oldItems, 0), - (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items, 0) + (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldItems, 0), + (oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items as IList ?? items.ToList(), 0) ); public override void Insert(int index, T item) diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedDictionary.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedDictionary.cs index 96dd9a5..99a39e0 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedDictionary.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedDictionary.cs @@ -53,7 +53,7 @@ public override void AddRange(IEnumerable> pairs) DoReadWriteNotify( () => 0, getIndicesAndInsert, - (nothing) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)pairsList) + (nothing) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, pairsList as IList ?? pairsList.ToList()) ); } diff --git a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedSet.cs b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedSet.cs index 79cb0c7..6e570fd 100644 --- a/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedSet.cs +++ b/Swordfish.NET.CollectionsV3/ConcurrentObservableSortedSet.cs @@ -95,7 +95,7 @@ public void RemoveRange(IEnumerable values) DoReadWriteNotify( () => _internalCollection.Count, (index) => ((ImmutableSortedSet)_internalCollection).RemoveRange(values), - (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)values, index) + (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, values as IList ?? values.ToList(), index) ); } */ @@ -139,7 +139,7 @@ public void Clear() // remove the keys from the dictionary, remove the range from the list (items) => ImmutableSortedSet.Empty, // Notify which items were removed - (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)items, 0) + (items) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items, 0) ); } diff --git a/Swordfish.NET.CollectionsV3/ImmutableDictionaryListPair.cs b/Swordfish.NET.CollectionsV3/ImmutableDictionaryListPair.cs index c0e7f3b..47751ae 100644 --- a/Swordfish.NET.CollectionsV3/ImmutableDictionaryListPair.cs +++ b/Swordfish.NET.CollectionsV3/ImmutableDictionaryListPair.cs @@ -151,7 +151,9 @@ public ImmutableDictionaryListPair RemoveRange(IList keys) var nodesToRemove = keys.Where(key => Dictionary.ContainsKey(key)).Select(key => Dictionary[key]); if (nodesToRemove.Any()) { - return new ImmutableDictionaryListPair(Dictionary.RemoveRange(keys), List.RemoveRange(nodesToRemove)); + var newDictionary = Dictionary.RemoveRange(keys); + var newList = List.RemoveRange(nodesToRemove); + return new ImmutableDictionaryListPair(newDictionary, newList); } else