user349026
user349026

Reputation:

"Properties" viewable in watch window / Debug view but call not invoked. C#

I had posted a question about stepping into properties Here Turned out to be problem a with VS2008 and went over to 2010. I was exploring properties and have hit a point where I need some clarity over how propety values are visible in watch windows but actual calls are not invoked.

When I try to view an objects property in watch window, I can see the value I had assumed that I would be seeing a null. So I put a breakpoint at the property and ran the program again, expecting it to break there. This did not happen. Now,

Below is the screen shot of what I see. Call for property is invoked in the next line that was commented out.

enter image description here

Here is my code that I was testing.

namespace ClassPropertiesView
{
    class A
    {
        public int timings
        {
            get
            {
                return objB.bTimes;
            }
        }

        public B objB
        {
            get
            {
                return new B();
            }
        }
    }

    public class B
    {
        public int bTimes
        {
            get
            {
                return -1;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            A anObject = new A();
     //       Console.WriteLine(anObject.timings);
        }
    }
}

Any help is appreciated. Thanks!

Upvotes: 1

Views: 824

Answers (1)

agent-j
agent-j

Reputation: 27923

As you are seeing, the breakpoints you have set in your methods will not be hit when you are using the watch window (and other VS debugging views).

I'm sure this is by design. If you have a modal Instant Watch window open, and you see a property, how is it going to show you the code behind your current window.

There is also a setting in Tools...Options... Debug\General called Allow property evaluation in variable windows. If you don't like the automatic invocation of your get_property method, you can turn it off.

Upvotes: 3

Related Questions