Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting of collections in watch window [visual studio code]

A long time ago I used Visual Studio and I remember that the watch window during debugging was much smarter in showing collections than in Visual Studio Code (which I am using now). For example, when I make a simple Listof Strings and I inspect this in the watch window in VSCode I get the following

enter image description here

Whereas in Visual Studio the quick watch feature was much more useful:

enter image description here

In general, I am mostly interested in the values in the collection, which I have to dig down fourlevels of hierarchy in vscode and is quite obfuscated. Does anyone know of an extension or a way to get a more usable watch window for collections?

like image 718
spassvogel Avatar asked Aug 14 '18 11:08

spassvogel


2 Answers

This won't universally reformat the debug watch window for list, but it may help you. You can add attributes to your classes which will modify the display of a classes member for instance DebuggerDisplay

[DebuggerDisplay("Count = {count}")]  
class MyHashtable  
{  
    public int count = 4;  
}  

This maybe useful, Another one that will come in handy is the DebuggerBrowsable this will automatically hide the root and display it's children

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]

These attributes will help control debugging on custom classes

like image 75
johnny 5 Avatar answered Oct 31 '22 20:10

johnny 5


There is currently no extension which could reformat the debug watch view content.

  • The OmniSharp/omnisharp-vscode plugin has no issue directly related to this.
  • A tool like DotNetTools is not directly pluggable into VSCode.
like image 34
VonC Avatar answered Oct 31 '22 19:10

VonC