Skip to content

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

Description

@oscar54321

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions