ReSharper 5 – Search with pattern

 

You may have already heard of ReSharper structural search, if you haven’t you may want to check out the following post:

http://blogs.jetbrains.com/dotnet/2010/04/introducing-resharper-50-structural-search-and-replace/

On my project we have a static helper class (It was there when I got here…) for loading and saving, which uses generic repositories underneath. It looks something like this:

FrameworkHelper.SaveEntity<T>(T entity)

 

I wanted to find out who was calling SaveEntity with a type of Person, using Find Usages would have brought back all the types. A text search would be equally useless because the generic parameters are implicit; a search on FrameworkHelper.SaveEntity<Person> would bring back nothing.

So let’s try and use the new ReSharper feature…

clip_image002

We get a dialog up so we can put in our search expressions. This runs against ReSharpers internal definition of the code, which is more intelligent than string based searching. We can tell it to look for all parameters which are a type of Person:

clip_image002[4]

This is our basic search, we want $frameworkHelper$ to evaluate to a type of FrameworkHelper, and $person$ to evaluate to a type of Person.

So let’s add some placeholders on the right panel. Since we want to specify the type explicitly we’ll use the Expression placeholder and specify the type of the expression:

clip_image004

And we’ll do exactly the same for the Person expression which turns the red expressions blue. We can now run the search and hopefully get the expected results:

clip_image006

Brilliant, exactly what we want. Just FYI a find usages on the SaveEntity method brings back 1476 results, manually going through all of those would have been a mission! Well 378 is also a lot, but at least its in the right direction :-)

blog comments powered by Disqus