ChangeTracking icon indicating copy to clipboard operation
ChangeTracking copied to clipboard

ChangeTrackingBindingList<T> imputes item type incorrectly when items of derived classes are added

Open oscar54321 opened this issue 4 years ago • 1 comments
trafficstars

When collection can contain items of different types (base type and derived type), InsertItem method (and other methods) assumes that items are of the same type (generic parameter). trackable = ChangeTrackingFactory.Default.AsTrackable(item should create trackable objects using actual parameter type, not from formal parameter type instead.

protected override void InsertItem(int index, T item)
        {
            object trackable = item as IChangeTrackable<T>;
            if (trackable == null)
            {
                trackable = ChangeTrackingFactory.Default.AsTrackable(item, ChangeStatus.Added, _ItemCanceled, _ChangeTrackingSettings, _Graph);
            }
            base.InsertItem(index, (T)trackable);
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
        }

oscar54321 avatar Oct 10 '21 15:10 oscar54321

Thanks for reporting, I verified that it is an issue, I will work on it as soon as I have a chance.

joelweiss avatar Oct 11 '21 01:10 joelweiss