为什么 VS2005 调试器不报告“base”。价值观正确吗? (是“为什么这个 if 语句失败?”)

发布于 2024-08-29 07:49:59 字数 1393 浏览 2 评论 0原文

我正在研究一个现有的类,该类是从 System.Windows.Forms.Combo 框派生的两个步骤。

该类因此覆盖 Text 属性:

    public override string Text
    {
        get
        {
            return this.AccessibilityObject.Value;
        }
        set
        {
            if (base.Text != value)
            {
                base.Text = value;
            }
        }
    }

“get”给出的原因是这个 MS bug: http:// /support.microsoft.com/kb/814346

但是,我更感兴趣的是“如果”不起作用。

有时,“base.Text != value”为 true,但按 F10 会直接进入“set”的结束 },并且 Text 属性不会更改。

我通过检查调试器中的值并在其上放置一个条件断点来看到这一点,只有当“if”语句的谓词为真时才会中断。

“如果”到底怎么会出错呢?

该类与 ComboBox 之间的类不涉及 Text 属性。上面的错误应该不会真正影响任何事情 - 它说它已在 VS2005 中修复。调试器显示的值是否与程序本身看到的不同?

更新

我想我已经发现这里发生了什么。

调试器错误地报告值(包括错误地评估条件断点)。要看到这一点,请尝试以下一对类:

class MyBase
{
    virtual public string Text
    {
        get
        {
            return "BaseText";
        }
    }
}

class MyDerived : MyBase
{
    public override string Text
    {
        get
        {
            string test = base.Text;
            return "DerivedText";
        }
    }
}

在最后一个 return 语句上放置断点,然后运行代码并访问该属性。

在我的 VS2005 中,将鼠标悬停在 base.Text 上会给出值“DerivedText”,但变量 test 已正确设置为“BaseText”。

那么,新问题:为什么调试器不能正确处理基数,我该如何处理?

I'm working on an existing class that is two steps derived from System.Windows.Forms.Combo box.

The class overrides the Text property thus:

    public override string Text
    {
        get
        {
            return this.AccessibilityObject.Value;
        }
        set
        {
            if (base.Text != value)
            {
                base.Text = value;
            }
        }
    }

The reason given for that "get" is this MS bug: http://support.microsoft.com/kb/814346

However, I'm more interested in the fact that the "if" doesn't work.

There are times where "base.Text != value" is true and yet pressing F10 steps straight to the closing } of the "set" and the Text property is not changed.

I've seen this both by just checking values in the debugger, and putting a conditional breakpoint on that only breaks when the "if" statement's predicate is true.

How on earth can "if" go wrong?

The class between this and ComboBox doesn't touch the Text property. The bug above shouldn't really be affecting anything - it says it's fixed in VS2005. Is the debugger showing different values than the program itself sees?

Update

I think I've found what is happening here.

The debugger is reporting value incorrectly (including evaluating conditional breakpoints incorrectly). To see this, try the following pair of classes:

class MyBase
{
    virtual public string Text
    {
        get
        {
            return "BaseText";
        }
    }
}

class MyDerived : MyBase
{
    public override string Text
    {
        get
        {
            string test = base.Text;
            return "DerivedText";
        }
    }
}

Put a breakpoint on the last return statement, then run the code and access that property.

In my VS2005, hovering over base.Text gives the value "DerivedText", but the variable test has been correctly set to "BaseText".

So, new question: why does the debugger not handle base properly, and how can I get it to?

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

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

发布评论

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

评论(2

っ〆星空下的拥抱 2024-09-05 07:49:59

使用 String.Compare 比较字符串。字符串有一些微妙之处。我无法告诉你为什么 if 会失败,除了你的字符串可能并不真正“相等”

Use String.Compare for comparing strings. There are subtleties with strings. I cannot tell you why the if would fail, other than that your strings might not really be 'equal'

爱她像谁 2024-09-05 07:49:59

...和 ​​ 只是总结我的新问题。啊好吧。

... and this just about wraps up my new question. Ah well.

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