• 10 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 8/6/19

Choose the way your value types are displayed

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:

Customize display in Data Tip
Customized display in Locals

And the icing on the cake is that this value is also displayed when you move the mouse over a variable in the editor:

Customized display in Data Tip
Customized display in Data Tip

Note that this Data Tip also contains the same little triangle to indicate that the fields can be displayed:

Possibility of seeing the properties
Possibility of seeing the properties

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. 😁

Example of certificate of achievement
Example of certificate of achievement