Sunday, November 27, 2005

Using DebuggerStepThroughAttribute

You can use System.Diagnostics.DebuggerStepThroughAttribute to prevent the Visual Studio debugger from stopping at the method/property call when you step through you code.

For example, you have a program like this :
1using System;
2using System.Diagnostics;
3
4namespace DebuggerStepThrough_Demo
5{
6 public class Employee
7 {
8 public Employee()
9 {
10 _name = "";
11 _salary = 0;
12 }
13
14 public Employee(string name, double salary)
15 {
16 _name = name;
17 _salary = salary;
18 }
19
20 private double _salary;
21 public double Salary
22 {
23 set { _salary = value; }
24 get { return _salary; }
25 }
26
27 private string _name;
28 public string Name
29 {
30 set { _name = value; }
31 get { return _name; }
32 }
33
34 public double IncreaseSalary(double amount)
35 {
36 Salary += amount;
37 return Salary;
38 }
39 }
40
41 class Class1
42 {
43 [STAThread]
44 static void Main(string[] args)
45 {
46 Employee emp = new Employee("My Name", 1000);
47
48 emp.IncreaseSalary(emp.Salary * 0.5);
49
50 }
51 }
52}
53



When you put a breakpoint at the line emp.IncreaseSalary(emp.Salary * 0.5);, and you step through the code in the debugger, the debugger will step into the get method of Salary property before the IncreaseSalary method. You can stop this by using the DebuggerStepThroughAttribute attribute.


1        public double Salary
2 {
3 set { _salary = value; }
4
5 [DebuggerStepThrough()]
6 get { return _salary; }
7 }
8



Now, when you step through the code again in debugger, the debugger will step into IncreaseSalary right away.

This is useful if your property getter and setter does not perform complex situation and you don't want
to step into those code during debugging.

Labels:

Method Navigation Key in VStudio

In Visual Studio, You can place your cursor on a method or property call and hit F12 to go to the method/property definition.

Similarly, when you are in the method/property definition, you can place your cursor on the method/property name, hit Shift+F12 to goto the method/property reference. Then you can use Ctrl+Shift+1 to move to the next reference or Ctrl+Shift+2 to move to the previous reference.

Labels:

Sunday, November 13, 2005

The Power of Blog

Blogging is such a wonderful innovation that allow individuals to share ideas and knowledge across the Internet.

I just found out someone has benefited from my ealier blog on the subject Javascript function override and has use that idea in his work.

Knowing this fact is a great motivation for me to continue blogging.