问题
I would like to re-factor various blocks of code throughout a project using ReSharper 7.1 Search / Replace with pattern.
The code blocks are similar to the following simplified example:
someControl.StatusProgressBar.IsIndeterminate = false;
someControl.StatusProgressBar.Visibility = Visibility.Visible;
someControl.StatusProgressBar.Minimum = 0;
someControl.StatusProgressBar.Maximum = 100;
someControl.StatusProgressBar.Value = percentage;
And I would like to change them to:
someControl.StatusProgressBar.Use(p =>
{
p.IsIndeterminate = false;
p.Visibility = Visibility.Visible;
p.Minimum = 0;
p.Maximum = 100;
p.Value = percentage;
});
'Use' is an extension method
This is easy enough if all the blocks of code are setting the same number of properties. The following search and replace patterns will do the job:
SEARCH
$someControl$.$SomeProperty$.$SubProperty1$ = $val1$;
$someControl$.$SomeProperty$.$SubProperty2$ = $val2$;
$someControl$.$SomeProperty$.$SubProperty3$ = $val3$;
$someControl$.$SomeProperty$.$SubProperty4$ = $val4$;
$someControl$.$SomeProperty$.$SubProperty5$ = $val5$;
REPLACE
$someControl$.$SomeProperty$.Use(p=>
{
p.$SubProperty1$ = $val1$;
p.$SubProperty2$ = $val2$;
p.$SubProperty3$ = $val3$;
p.$SubProperty4$ = $val4$;
p.$SubProperty5$ = $val5$;
});
However, if I also have a code block such as:
someControl.StatusProgressBar.IsIndeterminate = false;
someControl.StatusProgressBar.Visibility = Visibility.Visible;
someControl.StatusProgressBar.Minimum = 0;
someControl.StatusProgressBar.Maximum = 100;
someControl.StatusProgressBar.Value = percentage;
someControl.StatusProgressBar.Orientation = Vertical;
Is it possible, with ReSharper, to capture and replace both code blocks with one pattern? The later having one extra property setting but could easily be more than one extra or less.
I am thinking this is not possible. It would require the ability to create some kind of variable pattern and I can't see a way to do that, be it with regular expressions or otherwise.
Any ideas?
来源:https://stackoverflow.com/questions/13394071/resharper-search-and-replace-with-pattern