ChangeTracking icon indicating copy to clipboard operation
ChangeTracking copied to clipboard

Added MethodToSkip to public

Open Int32Overflow opened this issue 4 years ago • 4 comments

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

Int32Overflow avatar Sep 29 '21 11:09 Int32Overflow

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.

joelweiss avatar Oct 10 '21 23:10 joelweiss

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 avatar Oct 11 '21 07:10 Int32Overflow

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.

Int32Overflow avatar Oct 11 '21 10:10 Int32Overflow

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

joelweiss avatar Oct 11 '21 20:10 joelweiss