Go back to the same spot in debugging the T_WebPageTask unit test. CheckCreation with a breakpoint at the creation of the task variable. In the previous chapter, we went down into the constructor code using Step Into (F11
). If you go back up into the unit test code using Step Out (Shift
+ F11
), the Locals now show:
What's the difference between now, which displays what we would like, and WebPageTask, which shows only the name of its type as a value?
The debugger takes advantage of the fact that any .NET type implements the ToString method: thus this is called for each variable to calculate what is to be displayed.
Let's do this for WebPageTask:
public override string ToString()
{
return $"{Name} ({Category}) - {Url})";
}
If we rerun the unit test debugging, we'll get:
And the icing on the cake is that this value is also displayed when you move the mouse over a variable in the editor:
Note that this Data Tip also contains the same little triangle to indicate that the fields can be displayed:
Let's recap!
In this chapter, you learned how to customize the display of the value associated with the instance of a type making it easier to access its contents, rather than using its name. The next chapter shows you how to use a panel other than Locals to monitor variable values no matter what the execution context is. 😁