The DebuggerBrowsable attribute determines if and how a field or property is displayed in the debugger variable windows. Let's review the following code example:
public class VehicleSeries
{
private string _name;
public string Name
get { return _name; }
set { _name = value; }
}
private List<string> _vehicles = new List<string>();
public List<string> Vehicles
get { return _vehicles; }
set { _vehicles = value; }
The resulting display within the debugger is shown below:
Now lets remove duplicate information and show constituent vehicles by adding a few DebuggerBrowsable attributes:
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
This results in the following view in the debugger:
P.S. Also take a look at a tip "Use DebuggerDisplay attribute for a better debugger experience".
Add the DebuggerNonUserCode attribute above the 'get' and the 'set', and forget about the field. The debugger won't even step into the property code. Don't forget to turn on the 'Just my code' feature in the VS Debugger settings.
Adrian Aisemberg 12/5/2007 4:10:22 PM
IMHO the DebuggerStepThrough attribute serves better for this purpose - http://dotnettipoftheday.org/tips/DebuggerStepThroughAttribute.aspx
kostya.ly 12/6/2007 1:36:14 PM
When using the DebuggerNonUserCode attribute, you can still step into the code if you uncheck the 'Just my code' option. If you use the DebuggerStepThrough attribute, you cannot step into it, but only if you stop, edit and compile again without that attribute. So the difference is in the control. Means, you can choose at debug-time, if you still want to step into a 'hidden' code.
Adrian Aisemberg 12/6/2007 1:44:21 PM
In contrast to DebuggerNonUserCode, DebuggerStepThrough allows a breakpoint to be set in a method. Therefore if you want to step into the method marked with DebuggerStepThrough attribute, just set a breakpoint in it.
kostya.ly 12/6/2007 4:07:27 PM
Suppose you have a dll reference (not a project-reference), and still, you have the code of that dll (a real-world example). When you want to step into a method of that dll, if the method is marked with DebuggerStepThrough, you'll have to find that code and put the breakpoint in it. 'Go To Definition' won't help in this case. If the method is marked with DebuggerNonUserCode, just toggle the 'Just my code' feature (no need to stop the debugger for that) and step into it. The code will be loaded automatically without the need to locate it manually.
Adrian Aisemberg 12/21/2007 12:59:01 AM
Cool feature.. keep it posting such TIPS.
Nilesh 4/6/2010 3:21:37 PM