Print | Contents | Close |

Using DataTips and Setting Debugger Display Attributes

Learning objective

After completing this topic, you should be able to use a DataTip to edit a member of a complex data type and use Debugger Display attributes to modify how information is presented in the Visual Studio 2005 debugger.

Exercise overview

In this exercise, you're required to use a DataTip to edit a member of a complex data type, and use debugger display attributes to modify how information is presented in the Visual Studio 2005 debugger.

This involves the following tasks:

Task 1: Using DataTips to edit entries

Suppose you're currently debugging a short application. You notice an incorrect value in the code, and decide to replace this value using the extended DataTips feature in Visual Studio 2005 so that you can view the altered output.

Step 1 of 1

You want to change the name of the p1 code item to "Pears". You have already accessed the DataTip for p1 by hovering your cursor over it in the code.

Which steps do you perform to change the name of the variable using its DataTip?

Options:

  1. Click the + (plus sign) icon, select the "Apples" entry, type Pears, and press Enter twice
  2. Click the magnifying glass icon, click the "Apples" entry, type Pears, and press Enter twice
  3. Click the - (minus sign) symbol, click the "Apples" entry, type Pears, and press Enter twice

Result

To change the name of the p1 variable using its DataTip, you click the + icon, click the "Apples" entry, type Pears, and press Enter twice.

Task 2: Using display attributes

While debugging an application, you decide that you want to change the way types are displayed in the debugger windows.

Step 1 of 3

You decide to change the display properties of a string, which you have named "value".

Complete the code required to do this.



[MISSING CODE("{value}")]
internal class KeyValuePairs
{
private IDictionary dictionary;
private object key;
private object value;

public KeyValuePairs(IDictionary dictionary, object key, object value)
{
variables(value, key & dictionary);
this.value = value;
this.key = key;
this.dictionary = dictionary;
}
}

Result

You use DebuggerDisplay to alter the display properties of a string.

Step 2 of 3

When a type occurs at class level, you want the debugger to display a value of 50 in the value column in the debugger variable windows.

Which display attribute do you use to do this?

Options:

  1. DebuggerDisplay
  2. DebuggerHidden
  3. DebuggerNonUserCode

Result

You use the DebuggerDisplay attribute to customize how a type displays at class level.

Option 1 is correct. The DebuggerDisplay attribute controls how a member or type is displayed in the debugger variable windows and is applied at class level.

Option 2 is incorrect. The DebuggerHidden attribute is used by source code debuggers to hide code from the debugger.

Option 3 is incorrect. The DebuggerNonUserCode attribute identifies system code – code that the system, rather than a user, created. In Visual Studio 2005, enabling the Just My Code feature will prevent the debugger from displaying this code in debugger windows, unless the code contains an error.

Step 3 of 3

You want a specific type to display only public members in the debugger variable windows. However, you want to change the view of the type, without altering the type itself.

Which attribute do you use to do this?

Options:

  1. DebuggerDisplay
  2. DebuggerStepThrough
  3. DebuggerTypeProxy

Result

You use the DebuggerTypeProxy attribute to set the display proxy for a type, which will display only public members and won't change the type itself.

Option 1 is incorrect. The DebuggerDisplay attribute is applied at class level and controls how a member or type is displayed in the debugger variable windows.

Option 2 is incorrect. You use the DebuggerStepThrough attribute to tell the debugger to step through certain code, so that the code doesn't display in debugger windows – provided the Just My Code feature is enabled.

Option 3 is correct. You use the DebuggerTypeProxy attribute to customize the view of a type, without altering it, by specifying a display proxy for it. The debugger variable windows will then display only public members of the proxy.

The extended DataTips feature has now been used to edit the values in a complex data type, and debugger display attributes have been used to alter the way that types display in debugger windows.