如何创建 Visual-Studio 字符串可视化工具?
我试图为 IDictionary 或 ICollection 创建一个可视化工具
然后像简单的可视化工具一样(没有对话框;我的意思是悬停变量时出现的常用字符串可视化工具,请参见下图),我想制作自定义文本,我想投射集合到其类型的列表(即 StringCollection 到 List(Of String) 或 List),然后我将能够在可视化工具中看到它。 或者对于字典显示,列出键和值的可视化工具。
有什么想法如何实施,甚至如何开始?
我会尽快更新我的问题。
这是我想到的:
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;
}
}
}
这些是用于数组和多维数组的 VS 可视化工具:
我想要对 ICollection(或 IList)、IDictionary 等使用类似的东西。
请注意,在数组中,可视化工具显示每个嵌套的对象。 这实际上是我想要实现的:
。
尝试可视化一个列表,您将看到有一个私有值_items,因此您可以看到它的项目。 我想在集合和字典中实现类似的目标。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码项目上有很多示例。 这是我最有经验的一个:
我已经安装了 DataSet Visualizer我自己也用过它,所以我知道它有效。 它比您需要的更先进,因为它实际上显示整个 ADO 数据集,但代码应该很容易修改。
这里还有一些其他链接可供查看:
项目 1
< a href="http://www.codeproject.com/KB/vb/AuthoringVisualizers.aspx" rel="nofollow noreferrer">项目 2
There are a number of examples on Code Project. This is the one i have the most experience with: DataSet Visualizer
i have installed and used it myself so i know it works. Is is more advanced than you need since it actually displays entire ADO data sets but the code should be pretty easy to modify.
Here are a couple of other links to check out as well:
Project 1
Project 2
我发现已经存在的东西:
http://www.codeproject.com/KB /macros/ListVisualizer.aspx,但它仍然不会显示对象。
I've found somthing that already exists:
http://www.codeproject.com/KB/macros/ListVisualizer.aspx, but it will still not show objects.