All of the above attributes and techniques work
splendidly... when you have the source code and the luxury of being able to modify
it. What about when it is somebody else's code? What if it is a third party
component you want to adjust, or even a .NET Framework object? Fortunately,
you can apply all of the above Debugger attributes to any assembly via a file
called autoexp.cs. The autoexp.cs file is normally located in your My
Documents/Visual Studio 2005/Visualizers folder, where you will note there is
also an autoexp.dll. The .cs file gets compiled into the dll, which the
debugger uses for its debug-time visualizer behavior. In this file you will
find all kinds of examples of built-in visualizers for .NET types, which you
can customize and use as the basis for custom visualizers of your own. Listing
7 shows an example of some of the visualizers built into autoexp.cs.
Listing 7
// mscorlib
[assembly: DebuggerDisplay(@"\{Name ={Name} FullName = {FullName}}", Target = typeof(Type))]
// System.Drawing
[assembly: DebuggerDisplay(@"\{Name ={fontFamily.Name} Size={fontSize}}", Target = typeof(Font))]
[assembly: DebuggerDisplay(@"\{Name ={name}}", Target = typeof(FontFamily))]
[assembly: DebuggerDisplay(@"\{Color ={color}}", Target = typeof(Pen))]
[assembly: DebuggerDisplay(@"\{X = {x} Y ={y}}", Target = typeof(Point))]
[assembly: DebuggerDisplay(@"\{X = {x} Y ={y}}", Target = typeof(PointF))]
[assembly: DebuggerDisplay(@"\{X = {x} Y ={y} Width = {width} Height = {height}}", Target = typeof(Rectangle))]
[assembly: DebuggerDisplay(@"\{X = {x} Y ={y} Width = {width} Height = {height}}", Target = typeof(RectangleF))]
[assembly: DebuggerDisplay(@"\{Width ={width} Height = {height}}", Target = typeof(Size))]
[assembly: DebuggerDisplay(@"\{Width ={width} Height = {height}}", Target = typeof(SizeF))]
[assembly: DebuggerDisplay(@"\{Color ={color}}", Target = typeof(SolidBrush))]
// System.Web.UI.WebControls
[assembly: DebuggerDisplay(@"\{Text ={Text}}", Target = typeof(WebControls::Button))]
[assembly: DebuggerDisplay(@"\{Text ={Text}}", Target = typeof(WebControls::Label))]
[assembly: DebuggerDisplay(@"\{Text ={Text}}", Target = typeof(WebControls::HyperLink))]
[assembly: DebuggerDisplay(@"\{Text ={Text} Checked = {Checked}}", Target = typeof(WebControls::CheckBox))]
[assembly: DebuggerDisplay(@"\{Text ={Text} Checked = {Checked}}", Target = typeof(WebControls::RadioButton))]
[assembly:DebuggerDisplay(@"\{SelectedDate = {SelectedData}}", Target =typeof(WebControls::Calendar))]
[assembly: DebuggerDisplay(@"\{Text ={Text}}", Target = typeof(WebControls::LinkButton))]
// System.Web.UI.HtmlControls
[assembly: DebuggerDisplay(@"\{Value ={Value}}", Target = typeof(HTMLControls::HtmlInputButton))]
[assembly: DebuggerDisplay(@"\{InnerText ={InnerText}}", Target = typeof(HTMLControls::HtmlGenericControl))]
[assembly: DebuggerDisplay(@"\{Value ={Value}}", Target = typeof(HTMLControls::HtmlTextArea))]
[assembly: DebuggerDisplay(@"\{Value ={Value}}", Target = typeof(HTMLControls::HtmlInputText))]
[assembly: DebuggerDisplay(@"\{Value ={Value} Checked = {Checked}}", Target =typeof(HTMLControls::HtmlInputCheckBox))]
[assembly: DebuggerDisplay(@"\{Value ={Value} Checked = {Checked}}", Target =typeof(HTMLControls::HtmlInputRadioButton))]
Downloads
[Download Sample]