43.1. Attributes

This section begins by outlining a number of debugging attributes that can be applied to code to affect the way the debugger steps through it. Some of the debugging attributes can also be used to customize the appearance of your types when you hover over them in Break mode.

The debugging attribute classes are contained within the System.Diagnostics namespace. Rather than specify the full namespace for each attribute, the source code examples in this chapter assume that it has been added as an import.

43.1.1. DebuggerBrowsable

The first attribute you can apply to fields and properties that belong to a C# class is the DebuggerBrowsable attribute. Although this attribute can be applied to both C# and Visual Basic code, it is only interpreted by the C# debugger. This attribute takes a single parameter that determines how the member is displayed in the variable tree. In the following code snippet, the field Orders is set to Collapsed:

public class Customer
{
    [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
    public List<Order> Orders;

}

Figure 43-1 (left) shows the same snippet of code with DebuggerBrowsable initially set to Collapsed (or not specified). Figure 43-1 (center) shows the same snippet with DebuggerBrowsable set to the RootHidden value, where the actual Orders item does not appear, just the contents of the collection. Finally, in Figure 43-1 (right) the Never value is used for DebuggerBrowsable, in which case the Orders member does not appear at all. ...

Get Professional Visual Studio® 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.