5

When I try to see the internal list of Dictionary item I hate to expand every single node one by one. I'm looking for an easier way to do this.

For example:

I've got a Dictionary object Dictionary(Of AnotherObject, Integer) and I want see a property of AnotherObject as a list during the debug.

Normally I'd use this:

For Each item As DictionaryEntry(Of AnotherObject, Integer) in myDict
          Debug.Writeline(item.Name)
Next

But immediate window doesn't support loops.

Is there any practical way to do this in immediate window or debug visualizers?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
dr. evil
  • 26,944
  • 33
  • 131
  • 201

3 Answers3

3

Have you had a look at VS Visualizers?

A Generic List and Dictionary Debugger Visualizer for VS.NET

and

Write Your Own Visualizer for VS Debugging

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
  • You might want to write a visualizer that first transforms your List or Dictionary to a DataTable, and then uses the build in visualizer for that. The conversion to DataTable will use a schema that is specific to the type T. – Aviad P. Dec 30 '09 at 13:50
  • Awesome thanks, Visualise window is not resizable but hey :) Maybe I'll fix it later on. – dr. evil Dec 30 '09 at 15:08
  • n.b. The CodeProject ListVisualizer now has a resizable window. – richaux Jan 11 '13 at 15:58
2

While you can't use loops in the immediate window, it does allow you to declare new variables, so you can create new lists etc. which can then be displayed in the watch window.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
0

(ancient question, but. . .) I use LINQ for this quite a bit. Depending on what's present in the Immediate Window's context, you can either use the static members of System.Linq.Enumerable with extension method syntax or as ordinary static methods.

I'm going to use C# syntax 'cuz I have no idea what the VB syntax for this is (perhaps some VB wizard will come along and fix this).

I just performed the experiment of starting a small console project with Debug>Step Into New Instance. I found I had to load System.Core to get things going

System.Reflection.Assembly.Load("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
args.Select(arg => $"{arg}").ToArray()
System.Linq.Enumerable.Select(args, arg => $"{arg}").ToArray()

(Obviously arg is a string here and doesn't need to be converted to a string - I'm just using $"{arg}" to show a concise way of formatting something as a string)

(unless I'm totally misunderstanding the OP's intent) I think the equivalent for the OP would be something like

myDict.Keys.Select(key => $"{key.PropertyOfKey}").ToArray()

Additionally, you get the power of LINQ to manipulate what you display - Where, OrderBy, Skip, etc.

unbob
  • 331
  • 3
  • 7