无法在自动属性设置器上设置断点?为什么?

时间:2021-05-15 21:06:48

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

显然VS 2008不允许在自动属性的setter上设置断点。

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.

然后尝试在setter行上设置断点,整个auto-property变为断点 - 红色。

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?

这适用于普通属性,所以任何想法为什么自动属性得到这种特殊(限制性)处理?它们不仅仅是具有隐藏背景场的正常属性的语法糖吗?

4 个解决方案

#1


28  

Using Visual Studio 2008, 2010, 2012:

使用Visual Studio 2008,2010,2012:

  1. Go to the Breakpoint window
  2. 转到“断点”窗口
  3. New->Break at Function…
  4. 新 - >功能突破......
  5. For the get, type: ClassName.get_CurrentFramesize()

    对于get,请键入:ClassName.get_CurrentFramesize()

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

    对于set,键入: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.

当断点被击中时,你会得到一个“No Source Available”,但是你将获得调用堆栈中的调用位置。

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

我在这里找到了这个解决方案:http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/b1dd0dc3-e9c1-402a-9c79-a5abf7f7286a

See also: Debugging automatic properties

另请参阅:调试自动属性

#2


2  

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

简短的回答是:这个bug功能最终出现在VS2008的裁剪房间。

(Longer answer - hat tip @jdk)

(更长的答案 - 帽子提示@jdk)

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

我们得到的只是一个模糊的承诺,它被考虑用于vNext。

#3


1  

This feature is implemented in Visual Studio 2015

此功能在Visual Studio 2015中实现

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

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

#4


-2  

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.

不,你不能设置它们的断点,但那你会检查什么?用于存储auto-property的变量仅在运行时分配,因此没有用于显示/访问的调试器的变量。

#1


28  

Using Visual Studio 2008, 2010, 2012:

使用Visual Studio 2008,2010,2012:

  1. Go to the Breakpoint window
  2. 转到“断点”窗口
  3. New->Break at Function…
  4. 新 - >功能突破......
  5. For the get, type: ClassName.get_CurrentFramesize()

    对于get,请键入:ClassName.get_CurrentFramesize()

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

    对于set,键入: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.

当断点被击中时,你会得到一个“No Source Available”,但是你将获得调用堆栈中的调用位置。

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

我在这里找到了这个解决方案:http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/b1dd0dc3-e9c1-402a-9c79-a5abf7f7286a

See also: Debugging automatic properties

另请参阅:调试自动属性

#2


2  

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

简短的回答是:这个bug功能最终出现在VS2008的裁剪房间。

(Longer answer - hat tip @jdk)

(更长的答案 - 帽子提示@jdk)

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

我们得到的只是一个模糊的承诺,它被考虑用于vNext。

#3


1  

This feature is implemented in Visual Studio 2015

此功能在Visual Studio 2015中实现

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

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

#4


-2  

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.

不,你不能设置它们的断点,但那你会检查什么?用于存储auto-property的变量仅在运行时分配,因此没有用于显示/访问的调试器的变量。