ReSharper 2021.1 Help

Template Editor

Template Editor helps creating and editing code templates. Template Editor opens in a new document tab so that you can switch between the template and the application code to quickly test the created template.

ReSharper Template editor

Template Editor provides basic code highlighting for keywords, comments, and so on. All highlighting colors are configurable.

Configure highlighting colors for Template Editor

  1. Choose Tools | Options from the menu and then go to Environment | Font and Colors page.

  2. In the Display items list, find items that start with ReSharper Template Editor.

  3. Use the Item foreground selector to pick a color for the selected item.

The controls in the Template Editor can be divided into two logical groups, which are described in the following two tables:

Template Options

ItemDescription
ShortcutAvailable for live templates.
The shortcut (abbreviation) that you can type in your source code to invoke a live template.
DescriptionFor surround templates and file templates, this is the identifier that is displayed in the drop-down lists when you attempt to choose and apply a template. For live templates, this is an optional description string that pops up in the completion list together with the template shortcut.
Default file nameAvailable for file templates.
A default name that ReSharper prompts when you apply a file template.
File name must be a valid identifierAvailable for file templates.
This checkbox makes ReSharper check if the filename specified when applying the template is valid as a type identifier. This option is helpful if your template creates a file for a new type and the type name is initialized from the provided filename with the Current file name without extension macro. You can check the predefined file templates to see how it is implemented.
Shorten qualified referencesThis checkbox makes ReSharper automatically insert namespace import directives or remove qualifiers that become redundant after the template is applied. If this checkbox is not selected, ReSharper will not insert any namespace import directives.
ReformatThis checkbox makes ReSharper automatically reformats the expanded code fragment according to your formatting preferences settings.
AvailabilityThis hyperlink displays and allows modifying the scope of the template.
Add new fileAvailable for file templates.
This button adds a new empty file to a multi-file template.
Add file from existing templateAvailable for file templates.
This button adds a new file to a multi-file template by the reference to an existing file template.

Template parameters

ItemDescription
Parameter nameNames of template parameters as they are defined in the template body.
Choose macro or [name of a macro]This hyperlink displays or allows choosing a macro that calculates parameter value. By clicking this hyperlink you can choose a macro in the Choose Macro dialog. If the selected macro has a macro-parameter, is displayed in bold in the Choose Macro dialog (for example, format or type). In this case, after you choose a macro, a text field or a selector appears under the template parameter. You can specify the macro-parameter there.
Editable or Editable occurrence selectorThese controls allow you to make the parameter editable, in one of the following ways:
  • If the parameter is used in the template only once, make sure that the checkbox is selected.

  • If the parameter is used in the template more than once, a combo box appears, where you can select a sequential number of the editable occurrence. This number specifies to which occurrence of the parameter the input focus will be set when the template is deployed with a Hot Spot Session. You may also notice that the numbers are prefixed with 'M' or other letters. These letters define in which file of a multi-file template the input focus should be set for this parameter. 'M' stands for the main file and appears in all templates.

Move Up/ Move DownIf you select a parameter, you can use these buttons to change the order of parameters. The position in the list of parameters defines the order, in which the parameters are switched during the hot spot session when the template is applied. It affects only editable parameters.
Last modified: 08 March 2021