ReSharper Web Help

To create a code template from scratch
  1. On the main menu, choose ReSharper | Templates Explorer. The Templates Explorer window opens.
  2. Click one of three tabs corresponding to the required type of template: Live Templates, Surround Templates, or File Templates.
  3. Optionally, choose the layer by clicking its name in the Layer drop-down list.
  4. Click New Template . Template Editor appears in a new Visual Studio code pane:
  5. Identify your new template in one of the following ways:
    • For a live template, specify a shortcut (abbreviation) in the Shortcut field. A template shortcut is used to quickly invoke the corresponding template from the code editor. In the Description field, type optional description for the template.
    • For a surround template, specify the name of a new template in the Description field.
    • For a file template, fill in two text fields: Description (name of template) and Default file name (the file name that ReSharper suggests by default when a user invokes this particular template). Optionally, select File name must be a valid identifier to make ReSharper validate file name in the Create: [name of template] when you apply the template.
  6. To specify the availability context for the template, click the Available hyperlink. When the Select scopes dialog box appears, use check boxes to define where the new template can be applied.
  7. In the text area provided by the Template Editor, enter the template source code that may contain plain text and optional variables. Template variables (for example, $var$) appear in the list to the right of the text area as you type them. See Template Variables for details on template variables.
  8. Specify marcos for the variables. For guidelines, see Declaring Variables .
  9. Configure template formatting options:
    • Select the Reformat check box to make ReSharper automatically reformat the expanded code fragment according to your code style settings.
    • Select the Shorten qualified references check box to make ReSharper automatically insert namespace import directives or remove qualifiers that become redundant after the template is applied. If this check box is not selected, ReSharper won't insert any namespace import directives at all.

See Also