You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As in the title, i found that when i seed the AddRange with an IEnumerable, i have to explicitly call .ToList() for it to not throw InvalidCastException. seems to be an easy fix as seen here:
publicvoidAddRange(IEnumerable<TItem>items){using(_monitor.BlockReentrancy()){//this should be a condition where if the IEnumerable is of type (IList), then implicitly cast it. otherwise call .ToList()NotifyCollectionChangedEventArgse=newNotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,(IList)items,_list.Count);this.CollectionChanging?.Invoke(this,e);this.Adding?.Invoke(this,e);AddRangeInternal(items);OnPropertyChangedCountAndIndex();if(IsAddRangeResetEvent){this.CollectionChanged?.Invoke(this,newNotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));}else{this.CollectionChanged?.Invoke(this,e);}this.Added?.Invoke(this,e);}}
SabigGasim
changed the title
AddRange throws an InvalidCasaat
AddRange throws an InvalidCastException if the seeded parameter isn't of type IList<T>
Aug 10, 2023
Ah. Been out of the office. I will take a look at this. Your suggestion makes sense. I will also check to see if I can just cast it to IEnumerable. The MS NotifyCollectionChangedEventArgs may accept it. I'm not sure.
No description provided.
The text was updated successfully, but these errors were encountered: