“非公共成员”中的内容Visual Studio的“监视”窗口中的“节点”? [英] What goes in the "Non-Public members" node in Visual Studio's Watch window?

查看:261
本文介绍了“非公共成员”中的内容Visual Studio的“监视”窗口中的“节点”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio的对象中查看对象时,我假设C#对象的所有非公共(即私有,受保护,内部和内部受保护)成员都位于 非公共成员下。监视窗口。但是后来,我注意到了这样的代码:

I assumed that all Non-Public (ie, private, protected, internal, and internal protected) members of C# objects go under "Non-Public Members" when I look at objects in Visual Studio's Watch Window. But then, I noticed an anamoly with this code:

   class HashDerived : System.Security.Cryptography.HashAlgorithm { ... }

   HashAlgorithm hash1 = new HashDerived();
   HashAlgorithm hash2 = new System.Security.Cryptography.SHA1Cng();

hash1 的非公共成员看起来像这样:

hash1's "Non-Public Members" looks like this:

hash2 的非公共成员看起来像这样:

whereas hash2's "Non-Public Members" looks like this:

因此对于hash1,似乎只有 private 字段(m_bDisposed)出现在 非公共成员节点下,其中hash2 ,甚至还会显示受保护的和受保护的内部内部成员,例如 HashSizeValue和 HashValue。

So it seems like for hash1, only the private field (m_bDisposed) appears under the "Non-Public members" node, where for hash2, even protected and protected internal members like "HashSizeValue" and "HashValue" appear in it.

为什么会这样?这种行为背后的规则是什么?

Why does this happen? What are the rules behind this behaviour?

推荐答案

您在这里看到的行为是一个错误。在这种情况下,C#调试器不应显示静态成员。我已与代码库的当前所有者确认了这一点,他将为下一版Visual Studio提交一个错误。

The behavior you are seeing here is a bug. The C# debugger shouldn't be showing static members in this scenario. I confirmed this with the current owner of the code base and he's going to file a bug for the next release of Visual Studio.

发生这种情况的具体情况是

The specific scenario under which this happens is


  • 仅启用我的代码

  • 在确定为非用户程序集的类型中定义类型

  • 引用和对象实例的类型不同(开关 hash2 SHA1Cnf ,问题消失了)

  • Just My Code is enabled
  • The type is defined in what's determined to be a non-user assembly
  • The type of the reference and object instance are different (switch hash2 to SHA1Cnf and the problem disappears)

请注意,可能还会出现其他情况。这是我能够在调试/实验中缩小的行为。

Note there may be other scenarios where this appears. This is the behavior I was able to narrow down in the debugging / experimentation that I did.

这篇关于“非公共成员”中的内容Visual Studio的“监视”窗口中的“节点”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆