ReSharper 10.0 Help

Add/Edit/Search with Highlighting Pattern

ReSharper | Options | Code Inspection | Custom Patterns | Add Pattern/Edit
ReSharper | Find | Search with Pattern

This dialog box helps creating or editing custom patterns to detect code that matches specific pattern, and replace this code if necessary.

This topic describes controls in the dialog. To learn how to search and replace code with custom patterns, see Structural Search and Replace and Creating Custom Code Inspections and Quick-Fixes.

This dialog can be opened in two modes.

  • When you use the ReSharper | Find | Search with Pattern command, which is duplicated in the context menu of the editor, the dialog opens in the search/replace mode, allowing you to start the search or replace right from the dialog using the corresponding buttons on the bottom.
  • When you use the Add Pattern/ Edit buttons on the Code Inspection | Custom Patterns options page, the dialog opens in the pattern editing mode, providing additional fields for specifying pattern description. However, in this mode, the Search/ Replace buttons are not available.
Edit Highlighting Pattern dialog box
ItemDescription
Menu bar
Language selector Allows choosing a programming language for the pattern. ReSharper will only find the matching code in the specified language.
Find/Replace Use these selectors to show or hide the replace pattern.
Reference__Search_with_Pattern__Open_Catalogue Pattern Catalog Click to open the Code Inspection | Custom Patterns options 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
Search pattern Use this editor to 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 pattern editing 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 pattern editing mode) This field optionally lets you specify the description that is shown for the pattern on the Code Inspection | Custom Patterns options page. 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.
ReSharper's custom inspections. Descriptions for the inspection and the quick-fix
Replace area This area contains controls that help you create a replace pattern and specify actions after the replacement. This area appears when you select Replace in the right top corner of the dialog.
Replace pattern Use this editor to enter a replace pattern using plain text and placeholders. You can only use placeholders defined in the search pattern.
Format after replace Specify whether to apply formatting to the code produced by the replace pattern.
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.
Description (available in the pattern editing 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.
ReSharper's custom inspections. Descriptions for the inspection and the quick-fix
Placeholder area
Add Placeholder Click this button to create new placeholder. There are 5 types of placeholders:
  • Argument Placeholder - one or more arguments in a method invocation. If necessary, you can specify minimal or maximal number of arguments that should be matched.
  • Expression Placeholder - a sequence of operators and operands. You can optionally specify a type that is returned by this expression.
  • Identifier Placeholder - any symbol identifier. You can additionally specify a regular expression that will be used to match symbol names.
  • Statement Placeholder - a single-line statement that ends with a semicolon or a block of statements. If necessary, you can specify minimal or maximal number of statements that should be matched.
  • Type Placeholder - a value type or a reference type. By default, a placeholder of this kind will match any type, but you can specify a specific type explicitly.

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. Note that you cannot remove placeholders that are used in the search pattern.
Command buttons
Find (available in the find/replace mode when the replace pattern is hidden) Click this button to perform the search.
Replace (available in the find/replace mode when the replace pattern is shown) Click this button to find pattern occurrences and specify which of them to replace.
Save Click this button to save current pattern to the catalog using the smart save logic. To access the pattern catalog later, open the Code Inspection | Custom Patterns options page.
Save Copy (available in the pattern editing 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. Similarly to the 'Save' command, the smart save logic applies here.
Close Click this button to close the dialog box.

See Also

Last modified: 8 January 2016