TL DR
Does anyone know how to write Debug Visualizer for Visual Studio 2012 in C # so that I can render IEnumerable<string> , string[] or similar objects?
Additional Information
Visual Studio Debug Visualizer is great and I regularly use some of the popular ones ( Mole ). However, now is the time to release some custom visualizers. I started with a simple visualizer for the string:
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(My.Namespace.DebuggerSide), typeof(VisualizerObjectSource), Target = typeof(string), Description = "Awesome Visualizer")]
DebuggerSide code is basically an example from a template:
public class DebuggerSide : DialogDebuggerVisualizer { protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { if (windowService == null) throw new ArgumentNullException("windowService"); if (objectProvider == null) throw new ArgumentNullException("objectProvider"); var data = (string)objectProvider.GetObject(); using (var displayForm = new VisualizerForm(data)) { windowService.ShowDialog(displayForm); } } /// <summary> /// Tests the visualizer by hosting it outside of the debugger. /// </summary> /// <param name="objectToVisualize">The object to display in the visualizer.</param> public static void TestShowVisualizer(object objectToVisualize) { VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(DebuggerSide)); visualizerHost.ShowVisualizer(); } }
VisualizerForm is a custom form with additional controls, etc .... when I create a project and put the dll in the My Documents/Visual Studio 11/Visualizers folder and restart the visual studio, I really see that the debugger appears under the icon from glass when a breakpoint hits a string object. Woohoo! So far so good.
Now, instead of rendering string I would like to render string[] or IEnumerable<string> or a similar object. However, when I change the assembly attribute to IEnumerable<string> , this does not work, even the looking glass icon is not displayed on IEnumerable objects.
UPDATE
I can get it working by changing TargetType to List<> and then checking if I can use List<string> . However, this means that I need to drop all of my objects that I want to debug to List , and I cannot use IEnumerable<> or the string []