开发者

"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,

  • Are the values being shown in debug mode for the property just an additional feature by VS to allow the developer to see the property value, despite this a call should have been invoked
  • or Did I miss a setting? I know I have enabled the "Step in properties" options.
  • As soon as I specifically access the property, the break point hits as it should.

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

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

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜