Can't set breakpoints on an auto-property setter ? Why?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:31:24

问题


Apparently VS 2008 does not allow setting a breakpoint just on the setter of an auto-property.

I.e. if I define an auto-property like this:

    public int CurrentFramesize
    {
        get; 
        protected set;
    }

and then try to set a breakpoint on the setter line, the whole auto-property turns breakpoint-red.

This works just fine for normal properties, so any idea why auto-properties get this special (restrictive) treatment? Are they more than just syntactic sugar to normal properties with a hidden backing field?


回答1:


Using Visual Studio 2008, 2010, 2012:

  1. Go to the Breakpoint window
  2. New->Break at Function…
  3. For the get, type: ClassName.get_CurrentFramesize()

    For the set, type: ClassName.set_CurrentFramesize(int)

You'll get a "No Source Available" when the breakpoint is hit, but you'll get the calling location in the call stack.

I found this solution here: http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/b1dd0dc3-e9c1-402a-9c79-a5abf7f7286a

See also: Debugging automatic properties




回答2:


The short answer is: this bug feature ended up on the cutting room floor for VS2008.

(Longer answer - hat tip @jdk)

All we've got is a vague promise that it's being considered for vNext.




回答3:


This feature is implemented in Visual Studio 2015

http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/14/set-breakpoints-on-auto-implemented-properties-with-visual-studio-2015.aspx




回答4:


No you can't set a break point on them, but then what would you check? The variable for storage of the auto-property is only assigned at runtime and as such there isn't a variable for the debugger to show/access.



来源:https://stackoverflow.com/questions/2682613/cant-set-breakpoints-on-an-auto-property-setter-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!