Visualizer Visualizer for IEnumerable <string>

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 []

+6
source share
2 answers

Docs are documented as

Support for generic types is limited. You can write a visualizer for a target that is a generic type only if the generic type is an open type.

This means that you cannot write a visualizer that uses a private built type of type IEnumerable<string> . Have you tried setting the target type to IEnumeraable<> and then checking to see if elements of type string match?

+1
source

See the "Objects That May Have Debugger Visualization Options" section: https://rapiddevbookcode.codeplex.com/wikipage?title=EnumerableDebugVisualizer

My Enumerable Debugger Visualizer will work with IEnumerable, if the base concrete type is registered in it, you can look at the registration code to make your work work.

+1
source

Source: https://habr.com/ru/post/923965/


All Articles