Skip to main content
Rollback to Revision 1
Link
dugas
  • 12.3k
  • 3
  • 46
  • 53

Step into Properties while Debugging Hit Breakpoint When Caused by the Debugger

edited title
Link
Asad
  • 21.8k
  • 17
  • 71
  • 94

Hit Breakpoint When Caused by the Debugger Step into Properties while Debugging

Source Link
dugas
  • 12.3k
  • 3
  • 46
  • 53

Hit Breakpoint When Caused by the Debugger

Is there a way to have breakpoints hit when the action is caused by the Visual Studio debugger? For example, let's say I have the following (I know you shouldn't do this, just using it for argument's sake):

public class Test
{
    int _X = -1;
    public int X { 
        get { return ++_X; } //Breakpoint here
        set { _X = value; } 
    }
}

And:

static void Main(string[] args)
{

        Test t = new Test();
        t.X = 1;  //Breakpoint here
        return;
}

If you pause at the breakpoint in Main, every time you "hover" the mouse pointer over "t.X" (assuming you have the following Debugging option enabled - "Enable property evaluation and other implicit function calls") or you evaluate the property in the "watch" window - it will increment the property but the breakpoint in the property's "get" accessor will not be hit. Re-asking the question in a more specific context - is there a way to hit the breakpoint in the property's "get" accessor when the evaluation is done by the debugger?