Customize Your Debugger With Debugger Browsable

DebuggerBrowsable is one of the productive features in .Net that can improve your productivity and it allows you to customize your debugger. Developers need to do a lot of debugging and when they need to hide some of the properties from the debugger or they want to open in expanded mode, DebuggerBrowsable is really helpful. This is quite helpful in improving productivity.

To use the preceding attributes you need to use the System.Diagnostics namespace. If you want to customize the view on the debugger window for any properties during debugging you can easily do that using DebuggerBrowsable attributes. You can apply DebuggerBrowsable attributes for any properties, fields or for Indexer. The DebuggerBrowsable attributes constructor takes DebuggerBrowsableState as an argument. DebuggerBrowsableState is used to provide the instruction to the debugger of how to display it in the debugger window.

We have the following three states for DebuggerBrowsable attributes.

· Never indicates that the member is not displayed in the data window. For example, using this value for the DebuggerBrowsableAttribute on a field removes the field from the hierarchy; the field is not displayed when you expand the enclosing type by clicking the plus sign (+) for the type instance.

· Collapsed indicates that the member is displayed but not expanded by default. This is the default behavior.

· RootHidden indicates that the member itself is not shown, but its constituent objects are displayed if it is an array or collection.

Now let's see it with an example. Here we have two classes. The Employee class uses the Address Class.

We have applied [DebuggerBrowsable(DebuggerBrowsableState.Never)] to the Salary property of the Employeeclasss whenever we debug so we
won't find this property in the Debugger as in the following:

Now we marked Address with the DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] attribute and now we will debug it again.
We can see that the address is opening without the root. So whenever there is a need we have hundreds of properties andwe don't want to waste time in seeing all the properties that are not relevant or we want to see the property directly in expanded/collapsed mode we can use this feature and increase our productivity.

I hope this will help you in customizing your Debugger.