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.
[DebuggerDisplay]
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:
- 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( ) ).
- 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.
- The attribute is applied. Even when ToString( ) is implemented the DebuggerDisplay attribute will be applied.
Example:
[DebuggerDisplay(“Context= {_ctx.Brand}, {_ctx.CountryCode}”]
class SuffixSync
{
private readonly MyContext _ctx = MyContext.GetContext();
[ … ]
}
[DebuggerBrowsable]
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;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
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.
Reference:
http://msdn.microsoft.com/en-us/library/ms228992(VS.90).aspx