Before you can use a new pattern, you need to define placeholders. There are five types of placeholders:
- Argument - argument(s) in a method invocation
- Expression - a sequence of operators and operands
- Identifier - any symbol identifier
- Statement - a single-line statement that ends with a semicolon or a block of statements
- Type - a value type or a reference type
- On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
- Click Add Placeholder, then select a desired placeholder type in the list. The Create [Type] Placeholder dialog box opens.
- Type a name for a new placeholder in the Name text box and define other settings depending on the chosen type.
- Click OK to save the changes and add the placeholder to the list of defined placeholders.
After defining placeholders you can start creating a new pattern.
- On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
-
Pay attention that:
- By default, the Search with Pattern dialog box opens in the Find mode. So, if you want to create a replacement pattern just change the mode by clicking Replace on the menu bar.
- In spite of the fact that SSR works in C#, VB.NET, HTML and ASP.NET, C# language is used by default. So change the language, if necessary.
- Type code fragments in the text area using placeholders, plain text and standard language keyword syntax.
- If you want to save the recently created pattern, click Save. Otherwise, click Find or Replace.
- On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
-
Do one of the following:
-
Click Recent Searches
to display the list of recently used patterns, select the desired one.
-
Click Pattern Catalog
.
The Options dialog box opens. On the Custom Patterns pane
of the dialog box you can find all saved patterns and then invoke search or replace right from this dialog.
-
Click Recent Searches
You can easily bind SSR and code analysis. So that your search pattern is treated by ReSharper as an inspection, and your replacement pattern is treated as a quick-fix. In order to use a pattern as an inspection, you should raise the severity level for this pattern.
- On the main menu, choose ReSharper | Options. The Options dialog box opens.
- Click Custom Patterns on the left pane of the Options dialog box.
- All saved patterns are listed on the Custom Patterns pane. Each pattern has its own severity level. By default, Do not show is chosen. However, you can change it to Hint, Suggestion, Warning or Error. For more information, see Custom Patterns.
-
Click Save or Save To to apply changes.
ReSharper maintains several setting layers, so pay attention what layer you modify. For more information, see Managing and Sharing Options.
Note
After saving the changes all code fragments that match the pattern are highlighted in the editor.
It's good for visual perception, but not enough, especially when you have many patterns or
some of them are similar. In order to tackle these difficulties, a short description can be added
to any pattern. Consider the examples below:

- On the main menu, choose ReSharper | Options. The Options dialog box opens.
- Click Custom Patterns on the left pane of the Options dialog box.
-
Do one of the following:
- Click Add pattern on the Custom Patterns pane of the dialog box.
- Select the existing pattern, then click Edit.
-
Type some description for the search pattern in the Description text box.
Type some description for the replacement pattern in the Description text box.
Text boxes have the same labels, but they are displayed in different areas of the dialog box. For more information, see ReSharper Dialog Boxes: Add/Edit Highlighting Pattern
Note - Click Save or Save To to apply changes.
