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

But That's A Lot More Code To Write…

In our simple example here, we've taken the one property Person class and overhauled it with the Person2 class, the entirety of which is listed below as Listing 6.

Listing 6

[DebuggerDisplay("Person2:{Name}")]class Person2
{
 [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  private string _name;
  public string Name
  {
    [DebuggerStepThrough]get
    {
      return _name;
    }
    [DebuggerStepThrough]set
    {
      _name = value;
    }
  }
}

Clearly, there is a lot more code here than before and, arguably, the code is a bit tougher to read with all this attribute "clutter".  We can fix the latter easily enough through the use of a #region which can encapsulate the property in a named region (in this case called Name).  The end result is something we can easily collapse so that we are not faced with all this clutter while we are working with our Person2 class.  To do this, you could hand type #region Name and then #endregion, but a much more efficient way is to take advantage of Code Snippets.  In this case, you can simply highlight the lines you would like to place in a #region and right click, select Surround With, and then choose #region.  The #region statements are placed for you and the name of the region is highlighted in green and has focus, such that as soon as you start typing it will have whatever value you type for it.  Hit enter and the Code Snippet wizard completes, the green highlighting disappears, and you are left with your code.

Code Snippets are a fantastic feature of Visual Studio 2005.  If you have not used them yet, make a point to try them out.  There is no limit to the kind of code generation you can accomplish with these template-driven tools.  You can learn more about them, find others, and share your own at GotCodeSnippets.com

For more on Code Snippets, please see my related article, Visual Studio 2005 Code Snippets.


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-25 5:35:45 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search