Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, October 05, 2006

Simpler Debugger with DebuggerTypeProxy in .NET

Simpler Debugger with DebuggerTypeProxy

By default Visual Studio nests object properties in Watch Window and shows them in a hierarchy manner.  For more complex objects you need to traverse through your properties to find whatever you like.  This can be a pain when there are several unimportant properties for an object.

But there is a simple way to see what you need in Watch Window.  In order to be able to retrieve your desired properties with a pattern you like from an object in debugger, you only need to declare a class which has some properties (those that you're interested to watch).  This class must have a constructor that gets an object of same type of the class whose values are going to be monitored.  Once you wrote this class, will be able to declare a DebuggerTypeProxy attribute on your class definition which gets the type of your class as parameter.

Here is an example.  I have a Student class which has three properties:

  • Name: String value of student's name.
  • Age: Integer value of student's age.
  • Points: List<double> of student's points.

Now I put a Breakpoint to monitor myObject properties.

 Insert Breakpoint

Simpler Debugger with DebuggerTypeProxy

Post a Comment