cd491415
cd491415

Reputation: 891

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

Upvotes: 5

Views: 2690

Answers (2)

Omer Raviv
Omer Raviv

Reputation: 11827

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.

Upvotes: 5

Sнаđошƒаӽ
Sнаđошƒаӽ

Reputation: 17552

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.

Upvotes: 2

Related Questions