File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -19,21 +19,22 @@ public class ViewModelBase : ReactiveObject
1919 /// <param name="newItems">The new list of items.</param>
2020 protected static void UpdateObservableCollection < T > ( ObservableCollection < T > collection , IEnumerable < T > newItems )
2121 {
22- var newList = newItems . ToList ( ) ;
23-
22+ var newItemsSet = new HashSet < T > ( newItems ) ;
23+
2424 // Remove items that are no longer present
2525 for ( int i = collection . Count - 1 ; i >= 0 ; i -- )
2626 {
27- if ( ! newList . Contains ( collection [ i ] ) )
27+ if ( ! newItemsSet . Contains ( collection [ i ] ) )
2828 {
2929 collection . RemoveAt ( i ) ;
3030 }
3131 }
32-
32+
33+ var currentItemsSet = new HashSet < T > ( collection ) ;
3334 // Add new items that aren't already in the collection
34- foreach ( var item in newList )
35+ foreach ( var item in newItemsSet )
3536 {
36- if ( ! collection . Contains ( item ) )
37+ if ( ! currentItemsSet . Contains ( item ) )
3738 {
3839 collection . Add ( item ) ;
3940 }
You can’t perform that action at this time.
0 commit comments