Note that there are some explanatory texts on larger screens.

plurals
  1. POReSharper Search and Replace with Pattern
    text
    copied!<p>I would like to re-factor various blocks of code throughout a project using ReSharper 7.1 Search / Replace with pattern.</p> <p>The code blocks are similar to the following simplified example:</p> <pre><code>someControl.StatusProgressBar.IsIndeterminate = false; someControl.StatusProgressBar.Visibility = Visibility.Visible; someControl.StatusProgressBar.Minimum = 0; someControl.StatusProgressBar.Maximum = 100; someControl.StatusProgressBar.Value = percentage; </code></pre> <p>And I would like to change them to:</p> <pre><code>someControl.StatusProgressBar.Use(p =&gt; { p.IsIndeterminate = false; p.Visibility = Visibility.Visible; p.Minimum = 0; p.Maximum = 100; p.Value = percentage; }); </code></pre> <p><em>'Use' is an extension method</em></p> <p>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:</p> <p>SEARCH</p> <pre><code>$someControl$.$SomeProperty$.$SubProperty1$ = $val1$; $someControl$.$SomeProperty$.$SubProperty2$ = $val2$; $someControl$.$SomeProperty$.$SubProperty3$ = $val3$; $someControl$.$SomeProperty$.$SubProperty4$ = $val4$; $someControl$.$SomeProperty$.$SubProperty5$ = $val5$; </code></pre> <p>REPLACE</p> <pre><code>$someControl$.$SomeProperty$.Use(p=&gt; { p.$SubProperty1$ = $val1$; p.$SubProperty2$ = $val2$; p.$SubProperty3$ = $val3$; p.$SubProperty4$ = $val4$; p.$SubProperty5$ = $val5$; }); </code></pre> <p><br/></p> <p>However, if I also have a code block such as:</p> <pre><code>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; </code></pre> <p>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.</p> <p>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.</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload