How to create a visualizer string visualizer?

I tried to create a visualizer for an IDictionary or ICollection

Then, like a simple visualizer (without dialogue, I mean the visualizer of the input line that appears when the variable hangs, see the figure below), I want to create my own text, I want the collection to be included in its list of types (IE StringCollection to List (Of String) or List), and then I can see it in the visualizer. Or for dictionaries, show lists of visualizers for keys and values.

Any ideas on how to implement or even start?

I will update my question soon.

This is what I was thinking:

using System.Collections.Specialized; using System.Collections; namespace ConsoleApplication2 { static class Program { static void Main(string[] args) { System.Collections.Specialized.StringCollection collection = new StringCollection(); collection.AddRange(new string[] { "string1", "string2", "sting3" }); string[] visualizable = collection.ConvertToVisualizableList(); Dictionary<string,string> dic = new Dictionary<string,string> { {"key1","value"}, {"key2","value"} }; string[,] visualizable2 = dic.ConvertToVisualizableDictionary(); } static string[] ConvertToVisualizableList(this IList collection) { lock (collection) { if (collection == null) return null; int length = collection.Count; string[] list = new string[length]; for (int i = 0; i < length; i++) { object item = collection[i]; if (item != null) list[i] = item.ToString(); } return list.ToArray(); } } static string[,] ConvertToVisualizableDictionary(this IDictionary dictionary) { if (dictionary == null) return null; int length = dictionary.Count; string[,] list = new string[length, 2]; int i = 0; foreach (object item in dictionary.Keys) { list[i, 0] = item.ToString(); object value = dictionary[item]; if(value!=null) list[i, 1] = value.ToString(); i++; } return list; } } } 

These are VS visualizers for arrays and multidimensional arrays:

alt text

I want to use something like this for ICollection (or IList), IDictionary, etc.

Note that in arrays, the visualizer shows each nested object. In fact, I want to achieve :

d .

Try to visualize the list and you will see that there is a _items personal value so that you can see its elements. I want to achieve something similar in the collection and dictionary.

+1
source share
2 answers

The Code Project has a few examples. This is the one with which I have the most experience: DataSet Visualizer

I installed and used it myself, so I know that it works. It is more advanced than you need since it actually displays all the ADO datasets, but the code is pretty easy to change.

Here are a few other links to check:

Project 1

Project 2

+1
source

I found something that already exists:

http://www.codeproject.com/KB/macros/ListVisualizer.aspx , but it will not show objects anyway.

0
source

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


All Articles