November 19, 2009

Debugger/Editor Attributes

DebuggerDisplay - Use it to specify how a class or struct should be displayed in the debugger when the cursor hover over the item
[DebuggerDisplay("Count = {count}")]
class blahblahblah ...
DebuggerStepThrough - Instructs the debugger to step through that marked property or attribute, and not into it:
[DebuggerStepThrough]
public int Key
{
  [System.Diagnostics.DebuggerStepThrough]
  get { return key; }
  [System.Diagnostics.DebuggerStepThrough]
  set { key = value; }
}
DebuggerBrowsable - Determines if and how a field or property is displayed in the debugger variable windows.
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int key;
see also DebuggerDisplay and DebuggerBrowsable – Two Debugger Attributes you should know

EditorBrowsable - Use this 'EditorBrowsable' property to restrict intellisense/visual studio visibility of a property
[EditorBrowsable(EditorBrowsableState.Never)]
int MyProperty
...

DefaultValue - Then there is the 'DefaultValue' property that sets the default value of a C# class property. Used by visual designers, etc
[DefaultValue(42)] 
public int MyProperty { get; set; }

No comments: