I was trying to create a visualizer for IDictionary or ICollection
Then like the simple visualizer (without dialog; I mean the ususal string visualizer that appears when hovering the variable, see image below), I want to make my custom text, I want to cast the collection to its type's list (I.E. StringCollection to List(Of String) or List) and then I will be able to see it in the visualizer. Or for Dictionaries show to lists visualizers for keys and for values.
Any ideas how to implement or even how to start?
I will update my question soon.
This is something I thought about:
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 array and multidimentional arrays:
I want to use something similar for ICollection (or IList), IDictionary etc.
Note that in arrays, the visualizer shows every nested objcet. This is actually what I want to achieve:
.
Try to visualize a List and you will see that there is a private value _items, so you can see its items. I want to achieve something similar in collection and dictionary.