Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 993
DaveDev Avatar asked Dec 30 '25 13:12

DaveDev


1 Answers

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.
like image 92
Dmitry Osinovskiy Avatar answered Jan 03 '26 23:01

Dmitry Osinovskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!