Consider the fragment below:
[DebuggerStepThrough]
private A GetA(string b)
{
return this.aCollection.FirstOrDefault(a => a.b == b);
}
If I use F11 debugger doesn't skip the function instead it stops at a.b == b.
Is there any way to jump over this function rather than using F10?
IMO this is a bug in the C# compiler. The compiler should also place those attributes on the anonymous methods. The workaround is to fallback to doing the work manually that the C# compiler does for you:
[DebuggerStepThrough]
private A GetA(string b)
{
var helper = new Helper { B = b };
return this.aCollection.FirstOrDefault(helper.AreBsEqual);
}
private class Helper
{
public string B;
[DebuggerStepThrough]
public bool AreBsEqual(A a) { return a.b == this.B; }
}
But of course this is nasty and quite unreadable. That's why the C# compiler should have done this. But the difficult question for the C# team is of course: which of the attributes that you place on a method must be copied to internal anonymous methods and which should not?
I can see why it happens but don't have a way to get around it. Perhaps someone can build on this. The lambda expression gets compiled into an Anonymous Method.
I see: Program.GetA.AnonymousMethod__0(Test a)
Just like if you called another method in the method you've shown, pressing F11 would go into that method. eg/
[DebuggerStepThrough]
static A GetA<A>(IList<A> aCollection, string b) where A : Test
{
DoNoOp();
return aCollection.FirstOrDefault(a => a.b == b);
}
static void DoNoOp()
{
// noop
Console.WriteLine("got here");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With