问题
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
's "Non-Public Members" looks like this:
whereas hash2
's "Non-Public Members" looks like this:
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?
回答1:
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
- 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
toSHA1Cnf
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.
来源:https://stackoverflow.com/questions/11594725/what-goes-in-the-non-public-members-node-in-visual-studios-watch-window