当我在 Visual Studio 的观看窗口。但是后来,我注意到这段代码有一个异常:
class HashDerived : System.Security.Cryptography.HashAlgorithm { ... }
HashAlgorithm hash1 = new HashDerived();
HashAlgorithm hash2 = new System.Security.Cryptography.SHA1Cng();
hash1
的“非公共(public)成员”看起来像这样:
而 hash2
的“非公共(public)成员”看起来像这样:
因此对于 hash1,似乎只有 private
字段 (m_bDisposed) 出现在“Non-Public members”节点下,而对于 hash2,甚至 其中出现了 protected
和 protected internal
成员,如“HashSizeValue”和“HashValue”。
为什么会这样?这种行为背后的规则是什么?
最佳答案
您在这里看到的行为是一个错误。在这种情况下,C# 调试器不应显示静态成员。我与代码库的当前所有者确认了这一点,他将为下一个版本的 Visual Studio 提交错误。
发生这种情况的具体场景是
- 仅我的代码已启用
- 类型定义在确定为非用户程序集的地方
- 引用和对象实例的类型不同(将
hash2
切换为SHA1Cnf
,问题消失)
请注意,在其他情况下可能会出现这种情况。这是我能够在我所做的调试/实验中缩小范围的行为。
关于c# - Visual Studio Watch 窗口中的 "Non-Public members"节点是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11594725/