Visual Studio Debugger Tips and Tricks
page 5 of 7
by Steven Smith
Feedback
Average Rating: 
Views (Total / Last 10 Days): 36832/ 65

What About Others' Code?

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]


View Entire Article

User Comments

Title: DebuggerStepThrough does work for Property Accessors   
Name: Skip Valentine
Date: 2007-04-17 12:59:47 PM
Comment:
I got the DebuggerStepThrough to work on my property accessors as described in the article. I'm glad I came across this article, it'll trim down my debugger stepping experience.
Title: DebuggerStepThrough does not work for Properties   
Name: Hans Peter Bornhauser
Date: 2006-10-02 4:39:28 PM
Comment:
Unfortunately the DebuggerStepThrough's usage is not defined for properties. Therefore the above listing does not compile.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-28 1:48:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search