Resharper structural search and replace Part I - Searching
There isn't much documentation on Resharper's Structural Search and Replace
Consider the case where you want to find all the usages of the Text
property on a Windows Form
:
If you use Find Usages (Shift F12) you get all usages of any inheritor of System.Windows.Forms.Control
which isn't what we want in this case.
Enter Resharpers 'Search with pattern' (Alt-R,F,R)
which returns the following usages only:
I can hear the guys up the back saying 'you can already do that with Resharper's Advanced Find Usages (Ctrl+Shift+Alt+F12) but this only works in this instance because Text
is overridden by System.Windows.Form
- for a property of Form
that isn't overridden (eg form.Font
) then the above method is very effective in finding specific usages.
Other applications
You are searching for places where an Address
is added to a List<Address>
public class Address
{
}
static void SomeMethod()
{
var strings = new List<string>();
strings.Add("test1");
strings.Add("test2");//we dont want these usages.
strings.Add("test3");
var addresses = new List<Address>();
addresses.Add(new Address());//we want this usage only
}
Find Usages will return all usages of List<T>.Add
(which likely is very high in a real application)
Search with pattern to the rescue again!
This returns only the one usage above instead of 4 usages using F12. note, Resharper is showing the < as < in the UI but everything still works.
Last revised: 13 Apr, 2013 01:58 AM History
No new comments are allowed on this post.
Comments
No comments yet. Be the first!