Skip to content

Conversation

@Int32Overflow
Copy link

What does this change:
I need the function to pass through certain methods to the orginal target (like the funtion ToString or Equals).

Now you can add or remove method names which should be ignored.
ChangeTrackingFactory.Default.MethodsToSkip.Remove(nameof(Equals));

@joelweiss
Copy link
Owner

I am missing something, ToString() is not intercepted and is passed thru to the original target.

void Main()
{
    Order order = new Order { Id = 123 };
    var trackable = order.AsTrackable();
    Console.WriteLine(order.ToString());

    trackable.Id = 321;
    Console.WriteLine(order.ToString());
}

public class Order
{
    public virtual int Id { get; set; }
    public override string ToString() => $"Id={Id}";
}

puts out

Id=123
Id=321

If you can please clarify.
Thanks.

@Int32Overflow
Copy link
Author

Int32Overflow commented Oct 11, 2021

I am missing something, ToString() is not intercepted and is passed thru to the original target.

void Main()
{
    Order order = new Order { Id = 123 };
    var trackable = order.AsTrackable();
    Console.WriteLine(order.ToString());

    trackable.Id = 321;
    Console.WriteLine(order.ToString());
}

public class Order
{
    public virtual int Id { get; set; }
    public override string ToString() => $"Id={Id}";
}

puts out

Id=123
Id=321

If you can please clarify. Thanks.

I will check this and will add a Unit Test for this case.

@Int32Overflow
Copy link
Author

I was able to elicit the behavior. It is because of the "override" of ToString which causes this behavior. (This also happened before my change.)
If the ToString method was overridden, it will be called in the target and not the method in the proxy. However, if the method was not overridden, then it does not find this method in the target and automatically calls the proxy method. In this case, the MethodsToSkip works as expected.

@joelweiss
Copy link
Owner

please provide me with an example of what happens and what you expect to happen.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants