I'm attempting to output the values returned by a method using a breakpoint action. The method contains multiple non-identical return statements, similar to this example:
double Foo(int bar, int baz)
{
if (bar < 0)
return Math.Sqrt((double)(baz - bar) * (baz - bar));
if (bar % baz == 0)
{
if (baz == 3)
{
return bar / 2 * baz;
}
else
{
return Math.Pow(bar, baz);
}
}
return Math.Log(baz, bar);
}
I'm looking for a way to output the return value without resorting to refactoring the method such that it stores the value in a variable, or putting a breakpoint on each return statement and having to write an individual action for each one.
The accepted answer of this question shows that it's possible to inspect the return value using the $ReturnValue
keyword in the Immediate Window just before leaving the method.
The below image illustrates what I'd like to accomplish.
This won't work of course, and print:
DEBUG Result of Foo("1", false) = error CS0103: The name "$ReturnValue" does not exist in the current context.
While there are several keywords available, like $CALLER
or $TNAME
, I haven't found anything that will yield the return value.
Is it possible to print a return value in a single breakpoint action?