DaveDev
DaveDev

Reputation: 42185

Is there a Find & Replace function in ReSharper?

I've just implemented a custom MessageBox for my application. I'd now like to replace any calls to MessageBox.Show() with my custom implementation, which is MsgBox.Show()**. I realise I could do this with a simple global Find & Replace but I'm wondering if there's a safer/better way to do it with ReSharper?

**all the parameters being passed in are the same in both cases.

Upvotes: 3

Views: 2263

Answers (1)

Dmitry Osinovskiy
Dmitry Osinovskiy

Reputation: 10118

There is a tool called Structural search and replace in ReSharper. It is definitely safer to use than a simple Find & Replace, but it is a little bit more complex. I've tried to make an instruction for you, but I didn't test it. Try it on your own risk. Search Google for ReSharper structural search and replace to find more info.

  1. Go to ReSharper | Find | Search with pattern.
  2. Type $t$.Show($args$) in the text field.
  3. Click Add Placeholder -> Expression. Type t for name, then type MessageBox for expression type and choose the correct type from suggestion list.
  4. Click Add Placeholder -> Argument. Type args for name, leave other fields with default values.
  5. Ensure that this pattern finds your target calls by clicking Find.
  6. Now go back to ReSharper | Find | Search with pattern (your pattern should be still there).
  7. Click Replace.
  8. Type MsgBox.Show($args$).
  9. Click Replace.
  10. Now correct usings where necessary. Unfortunately, this only can be done semi-automatically, by finding errors via ReSharper's solution-wide analysis or by compiling your project and then clicking Alt-Enter on any error to invoke ReSharper's fix for adding usings.

Upvotes: 8

Related Questions