Skip to content

Can't create method to get interceptors #62

@sevek

Description

@sevek

I was wanting to create a custom method (to move to separate class later) that gets the list of Interceptors to add to the proxy.

I created a method

private IInterceptor[] GetInterceptors<T>(ChangeStatus status, Action<T> notifyParentListItemCanceled, ChangeTrackingSettings changeTrackingSettings, Graph graph) where T : class
{
    var changeTrackingInterceptor = new ChangeTrackingInterceptor<T>(status);
    var notifyPropertyChangedInterceptor = new NotifyPropertyChangedInterceptor<T>(changeTrackingInterceptor);
    var editableObjectInterceptor = new EditableObjectInterceptor<T>(notifyParentListItemCanceled);
    var complexPropertyInterceptor = new ComplexPropertyInterceptor<T>(changeTrackingSettings, graph);
    var collectionPropertyInterceptor = new CollectionPropertyInterceptor<T>(changeTrackingSettings, graph);

    return new IInterceptor[]
        {
            notifyPropertyChangedInterceptor,
            changeTrackingInterceptor,
            editableObjectInterceptor,
            complexPropertyInterceptor,
            collectionPropertyInterceptor
         };
}

and modified the proxy create to

var interceptors = GetInterceptors(status, notifyParentListItemCanceled, changeTrackingSettings, graph);
    object proxy = _ProxyGenerator.CreateClassProxyWithTarget(typeof(T),
        new[] { typeof(IChangeTrackableInternal), typeof(IRevertibleChangeTrackingInternal), typeof(IChangeTrackable<T>), typeof(IChangeTrackingManager), typeof(IComplexPropertyTrackable), typeof(ICollectionPropertyTrackable), typeof(IEditableObjectInternal), typeof(INotifyPropertyChanged) },
        target,
        GetOptions(typeof(T)),
        interceptors
        );

This all appears to work until I run the unit test where upon nearly all the collection tests fail.
I have done a similar thing with the TrackableChild and this doesn't cause unit test failures.

I tried putting inserting the returned interceptors using array notation so the statement was basically the same but to no avail. If any of the interceptors were from the called method one gets the errors.

I'm a bit at my wits end with this problem so I'm hoping someone can show me the error of my ways.

I was hoping to add validation and mixin capability as well as the ability to use interfaces (the latter of which I have working) but have stumbled at this.

I'm also wanting to create a version that doesn't make changes to the target until AcceptChanges is called but this seems like a complete rewrite.

Thanks Sevek

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