Rediscovered the Debug attributes

There are 2 attributes that can easily be applied to your classes / methods to modify the behavior at debugging time. The attributes don’t change the runtime behavior of your code.


This attribute defines how you’ll see a type or member in the debugger window (like the quick preview, Shift-F9).

There are 3 possibilities:

  1. This attribute is not applied, and the class doesn’t implement ToString( ). In this case the type of the object is shown (which is the default behavior of Object.ToString( ) ).
  2. This attribute is not applied, but the class implements ToString( ). The return value of ToString( ) is shown. Make sure that ToString( ) doesn’t change your object data, or that it doesn’t take ages to execute.
  3. The attribute is applied. Even when ToString( ) is implemented the DebuggerDisplay attribute will be applied.


[DebuggerDisplay(“Context= {_ctx.Brand}, {_ctx.CountryCode}”]
class SuffixSync
    private readonly MyContext _ctx = MyContext.GetContext();

    [ … ]




This attribute determines if and how a field or property is displayed in the debugger variable windows.

This example will prevent the debugger to show the e_gateway field:

class SuffixSync
    private readonly MyContext _ctx = MyContext.GetContext();
    private readonly IMediator _mediator;
    private readonly Gateway _gateway = new Gateway();


Other values for the enumeration are

  • DebuggerBrowsableState.Collapsed: shows the element as collapsed.
  • DebuggerBrowsableState.RootHidden: indicates that the member itself is not shown, but its constituent objects are displayed if it is an array or collection.



About Gaston

This entry was posted in .Net, Debugging, Development and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s