ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Structural Search and Replace

Last modified: 23 September 2024

Sometimes standard search methods, like searching for usages of a certain symbol or text occurrences that match some regular expression do not give the desired results. For example, you may need to find code smells specific to your project or find pieces of code that need to be refactored.

ReSharper allows you to find and, if necessary, replace blocks of code that match a specific pattern. These blocks may be quite different - they could contain different types, expressions, statements, and so on, but they would be logically similar. For example, you can create a general pattern that will match all foreach loops independently of what is iterated and what is inside the loop, or you can make this pattern more detailed to find only loops that iterate over a specific type. The pattern can be as complex as you need and have any desired level of detail.

All patterns that you create are stored in your pattern catalog and act as custom code inspections with custom severity levels. This means that all code blocks that match a specific pattern can be highlighted in the editor as hints, suggestions, warnings, or errors. Quick-fixes and fixes in scope could be also provided for the patterns — they could transform matched code blocks as defined in the 'replace' part of the pattern.

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the Languages and frameworks section.