“ VisualStudio 即时”窗口: 如何查看前100项以上的内容

我试图在 VisualStudio2005的即时窗口中查看具有超过300个属性的对象的属性。只显示前100个项目,后面跟着这个标题:

 < More... (The first 100 of 306 items were displayed.) >

我想看看其他的东西,但是想不出来。

我意识到我可以在“手表”窗口看到这些,但那不一样。

37536 次浏览

The immediate window was designed to be a quick view tool. If you want to see more detail, you will have to view it in either the Watch Window or the Quick Watch Window.

Another option is to write a Visual Studio AddIn that operates similarly to the Immediate Window, but has more options.

Sometimes its useful to see the list in the immediate window rather than looking in the watch window. You can easily see more results than the first 100 by using:

yourList.Skip(100).ToArray()

Which really doesn't take long to write and works well - was useful for me.

Update: As pointed out in the comments below, this answer is actually wrong and applicable ONLY to collections and NOT to objects with lots of properties. I'm leaving it here as lots of people seem to have found it useful.

If you add your object to the watch window, then expand the properties so that all are displayed. Then Ctrl+A and Copy. You can then paste in excel to get an organized list of properties and their values.

I always create an extension method to export objects to xml when debugging like this. It's very useful for troubleshooting object data. Here is what I use:

public static void SerializeToXML(this object entity)
{
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(entity.GetType());


System.IO.StreamWriter file = new System.IO.StreamWriter(string.Format(@"{0}\{1}.xml", Directory.GetCurrentDirectory(), entity.GetType().Name));
writer.Serialize(file, entity);
file.Close();
}

It's not 100% full proof, but most of the time it is perfect. It will create an xml file in the application directory with the objects name as the file name. In the immediate window you can just type the object name then .SerializeToXML().

so: myList.SerializeToXML()

Its an old question but to get the properties and values of an object during runtime a more reasonable solution with Quickwatch window is here:

  1. Open Quickwatch during Debug mode

Quickwatchwindow

  1. Type in your Variablename and press Enter

ModelExpression

  1. Press CTRL + A and CTRL + C in order to select and copy all Properties. You need to expand those which contains values and are non primitive types.

  2. Paste to your favorite editor.