简体   繁体   English

在调试器中显示 NameValueCollection 的值

[英]Display values of NameValueCollection in Debugger

I have a NameValueCollection with string keys and string values, like this:我有一个带有字符串键和字符串值的NameValueCollection ,如下所示:

fields["fieldname"] = "string value"

When I add a WATCH in VS20217 for "fields" it lets me expand a list of keys, but I don't seem to be able to get to the values unless I add an individual watch for each key.当我在 VS20217 中为“字段”添加一个 WATCH 时,它可以让我扩展一个键列表,但除非我为每个键添加一个单独的手表,否则我似乎无法获得这些值。

I seem to recall doing this thing in the past but can't recall the method.我似乎记得过去做过这件事,但想不起来方法。 Can anybody help?有人可以帮忙吗?

The low-friction approach would be to create an extension method first:低摩擦的方法是首先创建一个扩展方法:

public static string DebugView(this NameValueCollection nvc)
{
    return string.Join("\r\n", nvc.AllKeys.Select(key => $"{key}: {nvc[key]}"));
}

Then put nvc.DebugView() as your watch variable, or capture that string to a variable and put a watch on that instead of the NameValueCollection itself.然后将nvc.DebugView()作为您的监视变量,或者将该字符串捕获到一个变量中并对其进行监视而不是NameValueCollection本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM