Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio QuickWatch - How to find quickly an item in collection in QuickWatch window

I have observable collection called m_Tree. It contains objects of Planet type which has property Name. The collection could have hundreds of items in it. How do I quickly find a Planet.Name="Jupiter" in QuickWatch window in VS?

Currently, I have to manually expand each car in the collection and look for its Name but that can be troubling. Lambda expressions or LINQ do not work in QuickWatch as far as I can see.

Here is what I tried with LINQ

from item in m_Tree where item.Name == "Jupiter" select item

but QuickWatch shows error

from item in m_Tree where item.Name == "Jupiter" select item
Expression cannot contain query expressions

like image 593
cd491415 Avatar asked Jan 18 '17 23:01

cd491415


2 Answers

I created a commercial extension for Visual Studio that solves exactly this problem. OzCode replaces the normal QuickWatch and DataTip (hover over variable) windows. If you're just looking for the property value as text, you can use the Search feature:

Search

But if you want to "Jupiter" only when its the value in the "Name" property, not in any other property, you can use OzCode's Filter: Filter

And type in [obj].Name == "Jupiter" as your predicate.

like image 63
Omer Raviv Avatar answered Nov 15 '22 12:11

Omer Raviv


Though my answer is not about doing it in QuickWatch, it may help you get the job done.

While in debug mode, you can use the Immediate Window to do that. If not already open, open Immediate Window, and execute your query.

var jupiters = (from item in m_Tree where item.Name == "Jupiter" select item).ToList();
jupiters  // prints the objects in the Immediate Window

I use Immediate Window a lot, and find it very helpful. Hope that helps you too.

like image 38
Sнаđошƒаӽ Avatar answered Nov 15 '22 12:11

Sнаđошƒаӽ