ReSharper Web Help

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
Some more information you can find here:

To add a placeholder
  1. On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
  2. Click Add Placeholder, then select a desired placeholder type in the list. The Create [Type] Placeholder dialog box opens.
  3. Type a name for a new placeholder in the Name text box and define other settings depending on the chosen type.
  4. 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.

To create a new pattern
  1. On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
  2. 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.
  3. Type code fragments in the text area using placeholders, plain text and standard language keyword syntax.
  4. If you want to save the recently created pattern, click Save. Otherwise, click Find or Replace.
To use an existing pattern
  1. On the main menu, choose ReSharper | Find | Search with Pattern. The Search with Pattern dialog box opens.
  2. 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.

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.

To change a severity level for a pattern
  1. On the main menu, choose ReSharper | Options. The Options dialog box opens.
  2. Click Custom Patterns on the left pane of the Options dialog box.
  3. 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.
  4. Click Save or Save To to apply changes.

     Note

    ReSharper maintains several setting layers, so pay attention what layer you modify. For more information, see Managing and Sharing Options.

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:

To add a description
  1. On the main menu, choose ReSharper | Options. The Options dialog box opens.
  2. Click Custom Patterns on the left pane of the Options dialog box.
  3. Do one of the following:
    • Click Add pattern on the Custom Patterns pane of the dialog box.
    • Select the existing pattern, then click Edit.
    The Add/Edit Highlighting Pattern dialog box opens.
  4. Type some description for the search pattern in the Description text box. Type some description for the replacement pattern in the Description text box.

     Note

    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
  5. Click Save or Save To to apply changes.

See Also

Procedures

Reference