Skip to content
Cannot retrieve contributors at this time
66 lines (36 sloc) 2.78 KB

Filter Collections

With our Filter Collections feature, you can apply a filter expression to any collection


Filtering a collection in code is relatively easy and there are plenty of ways to do it.

But how do you filter while debugging?

For example, you have a collection of customer objects, and you’d like to filter the ones that are older than 35 years. Visual Studio’s Immediate Window and Watch Window don’t support lambdas. With our Filter Collections feature, you can apply a filter expression to any collection. To solve the customer problem, choose the collection of customers and set its filter to: DateTime.Today.Year – [obj].Birthday.Year > 35, press enter and see the results right away.

Once a collection is filtered, all the other features work on the filtered results as well.

Using Filter Collections

In order to run this demo click the Filter Collections button in the demo application.

Filter Collections button

(if you are running with Break on Exceptions, in which case you can skip the next step)

A message box with an exception will appear.

Close the message box and use the "Break on all CLR exceptions" button to stop once an exception is thrown.

Break on all CLR exceptions

Run the demo again. This time you should stop at the following method. Now it's easy to understand why the exception was thrown - we only have one eligible customer:

Exception origin

Looking at the code we see 31 customers going in the LINQ statement, but only one coming out.

Going through the customer collection one by one could take a while - instead lets filter it to show only the objects that follow a specific creteria.

  • Hover over the customers collection
  • Click on the magic wand
  • Choose Edit Filter

Edit Filter

Now we can update the collection filter, using [obj] as the filtered object, with intellisense support.

In this case we can use the following filter to try and see if the problem is that we do not have enough customers under 62:

[obj].Age < 62

Opening the Watch dialog (hover over customers) will show a small funnel.

Moving the pointer over the funnel will show that only 5 customers are under 62.

Age < 62

Clearly we have a problem. Now let's replace the filter condition to show all of the customers over 62.

Age > 62

We got quite a lot of customers there. Use Reveal to show the customer age by starring the Age property for one of the customers:

Customers with Age

Now all we need to do is find how the Age property was calculated and fix the bug.

Back to Main

You can’t perform that action at this time.