joelweiss/ChangeTracking

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

oscar54321 opened this issue · 1 comments

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));
        }

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