调试自动属性

发布于 2024-10-07 03:54:18 字数 146 浏览 0 评论 0原文

有没有办法在自动实现的属性中的 setter/getter 上设置断点?

int Counter { get; set; }

除了将其更改为标准属性(我正在这样做,但要做到这一点,我必须更改并重新编译整个项目)

Is there any way to set breakpoint on setter/getter in auto-implemented property?

int Counter { get; set; }

Other than changing it to standard property (I'm doing it in this way, but to do that I have to change and recompile whole project)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

独享拥抱 2024-10-14 03:54:18

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

  1. 转到断点窗口
  2. New ->在函数处中断...
  3. 对于 get,输入:ClassName.get_Counter()

    对于set,输入:ClassName.set_Counter(int)

您将得到一个“没有可用的源” 当断点被击中时,但是您将在调用堆栈中获得调用位置。

我在MSDN 上找到了这个解决方案

Using 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()

    For the set, type: 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.

I found this solution here on MSDN

酒废 2024-10-14 03:54:18

在 Visual Studio 2017 上:

将鼠标悬停在“set”一词上 ->右键单击->断点-> 在之前插入断点

“之前”

之后:

之后

On Visual Studio 2017:

Hover over "set" word -> right click -> Breakpoint -> Insert Breakpoint

Before:

Before

After:

After

吻泪 2024-10-14 03:54:18

这个问题很老了,但值得注意的是它只适用于 VS 2015。

https://devblogs.microsoft.com/devops/set-breakpoints-on-auto-implemented-properties-with-visual-studio-2015/

class X {
  public string name {
    set;
    get; // setting a breakpoint here will break in VS 2015!
  }
}

This question is very old but it is worth noting that it just works in VS 2015.

https://devblogs.microsoft.com/devops/set-breakpoints-on-auto-implemented-properties-with-visual-studio-2015/

class X {
  public string name {
    set;
    get; // setting a breakpoint here will break in VS 2015!
  }
}
裸钻 2024-10-14 03:54:18

如果我是你,我会暂时将该属性设置为由内部字段支持的标准属性...设置断点,然后你可以将其更改回来。

If I was you, I'd temporarily make the property a standard one backed by an internal field...set your breakpoints, and then you can change it back after.

盛夏尉蓝 2024-10-14 03:54:18

在设置属性或获取属性的地方设置断点,没有其他方法。

您可以通过查找所有引用选项来做到这一点

,并且由于它仅存储值并且在setter部分没有任何代码,那么您要调试什么?

Set Breakpoints where you are setting property or getting property, No other way.

you can do this by Find All References options

And Since it is only storing values and do not have any code in setter part so what do you debug?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文