是否有 .Net 属性来防止调试器中的属性评估?

Is there a .Net attribute to prevent property evaluation within the debugger?(是否有 .Net 属性来防止调试器中的属性评估?)

本文介绍了是否有 .Net 属性来防止调试器中的属性评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在框架中看到了几个具有这种行为的类(监视窗口中的刷新符号和警告).这是由属性控制的吗?如果是这样,我如何在我的库中模拟它?

I've seen several classes in the framework with this behavior (a refresh symbol in the watch window, and a warning). Is this controlled by an Attribute? If so, how can I emulate this in my library?

感谢您的信息!为了澄清,我正在开发一个具有必须从单个线程访问数据的属性的框架.不幸的是,由于监视窗口等原因,当我在调试器中时,我遇到了一些奇怪的行为.我对 Debugger Browsable 属性有经验;但是,我更愿意在主线程访问/设置它们之后显示属性.我已经看到,尤其是在 IEnumerables 中,调试器不会在没有用户输入的情况下进行评估....有没有办法将这些属性标记为需要隐式评估",或者我可以不吃蛋糕吗?

Thanks for the info! To clarify, I am developing a framework with properties that must access data from a single thread. Unfortunately, I am getting some odd behavior when I am in the debugger because of watch windows, etc. I have experience with the Debugger Browsable attribute; however, I would prefer to display the properties after the main thread has accessed / set them. I have seen, especially in IEnumerables that the debugger will not evaluate without user input. ...Is there any way to flag these properties as requiring "Implicit Evaluation", Or can I not have my cake and eat it too?

推荐答案

这不受属性控制.这是调试器的固有特性.

This is not controlled by attributes. It's an inherent feature of the debugger.

此功能的根本原因是防止用户进行不必要的功能评估.Func Eval 是调试器中的一项危险操作,可能会导致显着减速或损坏程序状态.调试器会非常小心地确保它不会无意中执行可能会降低您的调试体验的额外 func eval.

The underlying reason for this feature is to prevent unwanted function evaluations by the user. Func Evals are a dangerous operation in the debugger and can cause significant slow downs or corrupt program state. The debugger takes great care to make sure that it doesn't inadvertently do extra func evals that may degrade your debugging experience.

如果 watch/locals/auto 窗口中的某个项目可能导致 func eval 并且调试器不认为应该发生 func eval,则该值将变灰并且刷新按钮将出现在值列.单击该按钮告诉调试器,不,我真的想评估那个表达式".

In the case where there is an item in the watch/locals/auto window that may cause a func eval and the debugger does not believe a func eval should happen, the value will grey out and a refresh button will appear in the value column. Clicking on that button is telling the debugger, "no really I want to evaluate that expression".

在调试器中发生这种情况的原因有很多.以下 2 种可能性最大.

There are many reasons why this will happen in the debugger. The following 2 though are the most likely.

隐式属性评估已禁用

工具 ->调试器->选项->启用隐式属性评估

Tools -> Debugger -> Options -> Enable Implicit Property Evaluation

如果未选中此值,您是在告诉调试器请不要自动评估属性.引擎盖下的属性只是函数调用.它们通常比普通函数调用更安全,但并非总是如此.

If this value is unchecked, you are telling the debugger please don't auto-evaluate properties. Properties under the hood are just function calls. They are generally safer than normal function calls but not always.

但您仍然可以通过直接在监视窗口中键入属性来强制对其进行评估.如果连续键入 2,第一个值将变为陈旧".这是因为在监视窗口中键入第二个表达式将导致所有其他表达式被重新计算.为什么?因为评估任何表达式的行为都可能改变其他表达式的结果.

But you can still force properties to evaluate by typing them directly into the watch window. If you type 2 in a row, the first value will become "stale". This is because typing a second expression in the watch window will cause all other expressions to get re-evaluated. Why? Because the act of evaluating any expression could have altered the results of the others.

因为隐式 func eval 已关闭,第一个属性将不会自动评估,您必须强制它.

Because implicit func eval is turned off the first property will not auto-evaluate and you must force it.

Func Eval 和 Step

如果您将表达式添加到执行函数评估的监视窗口,然后执行单步操作,则该值将在监视窗口中过期".

If you add an expression to the watch window which does a function evaluation and then do a step operation, the value will be "staled" in the watch window.

这样做的原因有很多,但影响最大的原因之一是提高性能.用户在监视窗口中键入许多表达式是很常见的,并且进行函数评估肯定并不罕见.一次一个,这些都不是很慢.但想象一下,您正试图快速浏览一些代码,并且在监视窗口中有 10 个 func eval.这会迅速增加并显着降低您的踏步体验.所以 func evals 不会自动重新评估.

This is done for many reasons, one of the most impactful reasons though is stepping performance. It's very common for a user to type many expressions in the watch window, and it's definitely not rare to have a function evaluation. One at a time these aren't very slow. But imagine you're trying to step quickly through some code and you had 10 func evals in the watch window. That can quickly add up and significantly degrade your stepping experience. So func evals are not automatically re-evaluated.

这篇关于是否有 .Net 属性来防止调试器中的属性评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:是否有 .Net 属性来防止调试器中的属性评估?

基础教程推荐