View Stream Window Content in Visual Studio QuickWatch

How to view the contents of a stream in a QuickWatch window in Visual Studio?

Update

According to Daniel's answer, I used the following code -

System.Text.Encoding.UTF8.GetString((byte[])stream.GetType().GetMethod("InternalGetBuffer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(stream, null))

+5
source share
2 answers

You can view the content MemoryStreamwithout changing it, if you can make some assumptions:

  • Your flow really is MemoryStream
  • Your stream contains only string data
  • You know the encoding of this string, for example. UTF8 or ASCII

If you can make these assumptions, you can use the following code in the Clock window:

Encoding.UTF8.GetString((byte[])stream.GetType().GetMethod("InternalGetBuffer", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(stream, null))

:
, , .

+4

, , QuickWatch , , (, ) - , stream .

, , .


, MemoryStream byte GetBuffer(), byte , .

+2

All Articles