ReSharper 8.0 Web Help

ReSharper | Find | Search with Pattern

This dialog box helps create and edit a custom code pattern, and, optionally, a replace pattern for it. You can access this dialog box from:

  • the main menu (ReSharper | Find | Search with Pattern) to specify a new search (and replace) pattern. In this case, you will be able to run the search right from this dialog box.
  • the context menu of a selection in the editor (Find Similar Code). In this case, the selected code will be used as a base for the search pattern.
  • the ReSharper options, on the ReSharper Options | Code Inspection | Custom Patterns page. Here you can find all existing patterns, edit them, add new ones, and run the search with any of the patterns.

For more information, see Structural Search and Replace and Creating Custom Code Inspections and Quick-Fixes.

Depending on your goals, you can switch two modes in the dialog box:

Find mode

By default, the Search with Pattern dialog box opens in the Find mode. The controls that are available in this mode are described in the table below.

Reference__Search_with_Pattern_01

Item Description
Menu bar This area contains menu items.
Language selector Allows choosing a programming language of the pattern. ReSharper will only find the matching code in the specified language.
Find Click this button to switch to the Find mode.
Replace Click this button to switch to the Replace mode.
Reference__Search_with_Pattern__Open_Catalogue Pattern Catalog Click to open the ReSharper Options | Code Inspection | Custom Patterns page and look through the list of existing patterns.
Reference__Search_with_Pattern__Recent_Search Recent Searches Click to expand the list with recently used custom patterns.
Search area This area contains controls that allow you to create a custom pattern and specify search options.
Search pattern In this area, enter your own search pattern using plain text and placeholders.
Look in (available in the 'Find/replace' mode) Use the drop-down list to specify one of the following search scopes:
  • Entire Solution
  • Current Project
  • Current File
Pattern severity (available in the 'edit pattern' mode) If you use the pattern as a custom code inspection, you can use the drop-down list to specify its severity level.
Match similar constructs Use this control to specify whether to match similar constructs.
ReSharper considers following constructs as similar:
  1. Single-line statement and single-line statement that is enclosed in braces.
  2. Binary expressions as they are specified in the pattern and in reverse order.
  3. Expressions as they are specified in the pattern and expressions with different order of operands.
  4. Expressions where operands are enclosed in parentheses and expressions where operands are not enclosed.
  5. Postfix and prefix increment operators.
  6. Methods with different access modifiers.
Description (available in the 'edit pattern' mode) This field optionally lets you specify the description that is shown for the pattern in the pattern catalogue. If you use the pattern as a custom code inspection, this description appears as a tooltip for highlighting the corresponding issues in the editor, as well as in the inspection results.
Placeholder area This area contains controls that help you create placeholders and manage them.
Add Placeholder Click this button to create new placeholder. There are 5 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

Tip

You can just type a new placeholder usage in the search pattern area, e.g. $statement$, and the new placeholder will be added to the placeholder list, where you can edit its type and parameters.

On clicking this button, the Create Placeholder dialog box opens, where you can choose the type of the placeholder, specify its name and parameters:

create_argument_placeholder

The following controls can be used in this dialog box:

  • Name - specify the placeholder name (for all placeholders).
  • Limit minimal number of arguments/statements - define minimum number of placeholder occurrences (for argument and statement placeholders)
  • Maximal - define maximum number of placeholder occurrences (for argument and statement placeholders)
  • Expression type/Type - select an item from the drop-down list to specify the type of placeholder (for expression and type placeholders)
  • Or derived type - select this check box to match expressions or types which have chosen type or its derived types (for expression and type placeholders)
  • Identifier name regexp - define regular expression for identifier name (for identifier placeholder)
  • Case sensitive - specify whether the identifier is case sensitive (for identifier placeholder)
Edit Click this button or double-click at the placeholder name to edit the selected placeholder using the Create/Edit Placeholder dialog box.
Remove Click this button to remove the selected placeholder.
Command buttons Command buttons that are available in this dialog box and are used to initiate immediate actions.
Find (available in the 'Find' mode) Click this button to perform the search.
Save Click this button to save current pattern to the catalog. To access the pattern catalog, open ReSharper Options | Code Inspection | Custom Patterns.
Save Copy (available in the 'edit pattern' mode) Click this button to save a copy of the current pattern to the catalog. This may be helpful if you want to create a new pattern similar to the current pattern.
Close Click this button to close the dialog box.

Replace mode

Most controls in the Replace mode are completely the same as in the Find mode. The table below describes additional controls that appear in the Replace mode:
Reference__Search_with_Pattern_02

Item Description
Replace area This area contains controls that allow to create a replace pattern and specify actions after the replacement.
Replace pattern In this area enter a replace pattern using plain text and placeholders.
Format after replace Specify whether to apply formatting to code.
You can configure code formatting options in the Code Editing | General Formatting Style options page and/or Code Editing | [Language] | Formatting Style options pages.
Shorten references Specify whether to replace fully qualified names with short names.
Command buttons Command buttons that are available in this dialog box and are used to initiate immediate actions.
Description (available in the 'edit pattern' mode) This field optionally lets you specify the description that appears as the name of the quick-fix if you use the pattern as a custom code inspection.
Replace (available in the 'Replace' mode) Click this button to find pattern occurrences and specify which of them to replace.