简体   繁体   English

自动实现的属性设置器上的条件断点

[英]Conditional breakpoint on auto-implemented property setter

Say I have this auto-implemented property in class ClassName: public int Counter{ get; set; } 假设我在类ClassName中具有此自动实现的属性: public int Counter{ get; set; } public int Counter{ get; set; }

I have not successfully been able to have a conditional breakpoint on a C# auto-implemented property setter in Visual Studio 2013. Specifically, on the new value being set. 我未能成功在Visual Studio 2013中的C#自动实现的属性设置器上有条件断点。特别是在设置新值时。 (I would like to breakpoint it when it is set to a negative number, for example.) (例如,当它设置为负数时,我想对其进行断点设置。)

I know there are other solutions, like breaking out the property so that it isn't an auto-implemented property, or breakpointing all places that set that property. 我知道还有其他解决方案,例如将属性设置为非自动实现属性,或对设置该属性的所有位置进行断点设置。 But I would love to just be able to do it without tedious workarounds. 但是我很乐意在没有繁琐的解决方法的情况下能够做到这一点。

I have successfully breakpointed on an auto-implemented property setter using the following tip from https://stackoverflow.com/a/6713867/119418 我已使用https://stackoverflow.com/a/6713867/119418的以下提示成功在自动实现的属性设置器上断点

Using Visual Studio 2008, 2010, 2012, 2013: 使用Visual Studio 2008、2010、2012、2013:

  1. Go to the Breakpoint window 转到断点窗口
  2. New->Break at Function… 新功能->功能突破...
  3. For the get, type: ClassName.get_Counter() 对于获取,请输入: ClassName.get_Counter()

    For the set, type: ClassName.set_Counter(int) 对于集合,键入: ClassName.set_Counter(int)

You'll get a "No Source Available" when the breakpoint is hit, but you'll get the calling location in the call stack. 命中断点时,您将获得“无可用源”,但您将在调用堆栈中获得调用位置。

Not exactly the answer to the question (for Visual Studio 2013), but breakpointing on getters and setters is expected to work in Visual Studio 2015. (对于Visual Studio 2013)问题的答案并不完全,但是在getter和setter上的断点有望在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

im not 100% sure what your trying to do if i got this correct you just want to set a breakpoint to a property if someone sets it to a negative value 即时消息不是100%确定如果我正确就做些什么,如果有人将其设置为负值,则只想为属性设置一个断点

i could be be heading in the wrong direction here but are you looking for this kind of thing 我可能会朝错误的方向前进,但您是否正在寻找这种东西

private int _age;
public int Age
{
      get{ return _age;  }
      set{ 
        if(value < 0) 
        { throw somthing;} //add a breakpoint here 
        else{ _age = value;} 
         }
}// im writing this directly in the browser so forgive space indentation etc 

this may not be exactly what you want but i do see it as the easiest way to achieve what your asking 这可能不完全是您想要的,但我确实将其视为实现您的要求的最简单方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM