ReSharper Web Help

ReSharper | Live Templates | Live Templates / Surround Templates / File Templates | ... | [name of template] | Edit

Template Editor is a new user interface for editing ReSharper templates introduced in ReSharper 4.0. It opens in a new Visual Studio code pane, allowing you to switch between your code and your template editing environment to make real-world testing of templates faster:

The following two tables describe controls in the Template Editor that can be divided into two logical groups:

Template Options

Item Description Comments
Shortcut

Go to top

In this field, you should specify the shortcut (abbreviation) that you can type in your source code to invoke the template.

Available for live templates.

Description

Go to top

For surround templates and file templates, this is the identifier that is displayed in drop-down lists when you attempt to choose and apply a template. For live templates, this is the description string that is displayed in drop-down lists to the right of a template shortcut.

Available for all three types of templates.

Default file name

Go to top

Type a default name that ReSharper will suggest in the Create [template description] dialog box when you apply the template.

Available for file templates.

File name must be a valid identifier

Go to top

If this check box is selected and the default file name that you entered doesn't meet requirements for valid identifiers, ReSharper displays an error message in the Create: [name of template] dialog box when you attempt to apply the template.

Available for file templates.

Available...

Go to top

By clicking the link, you specify availability scope for the template in one of two dialog boxes:

  • Template Availability (for live templates and surround templates):
  • Template Options (for file templates):

The following options are available in the Template Availability dialog box:

  • Language-specific: makes the template available for a specific language (select the language from the drop-down list). For C# templates, you can specify a language version in the Minimum C# version drop-down list. You can further narrow down the availability of a template by selecting the following check boxes:
    • Everywhere (C#, VB.NET, XML).
    • Where expression is allowed (C#, VB.NET).
    • Where statement is allowed (C#, VB.NET).
    • Where query clause is allowed (C# 3.0).
    • Where member declaration is allowed (C#, VB.NET).
    • Where namespace declaration is allowed (C#, VB.NET).
    • Where tag is expected (XML).
    • Where attribute is expected (XML).
  • All text files: makes the template available in all text files.
  • File mask: makes the template available only for files with names that match the given mask. Masks let you create custom language-specific templates, for example, for editing HTML, XML or even C++ files.

The following options are available in the Template Options dialog box:

  • Everywhere: makes the template available in all projects, irrelevant of the language that they're coded in.
  • Only in projects for language: makes the template available in all projects or in language-specific groups of projects. Possible options are:
    • C# projects (including ASP.NET C# projects)
    • All projects
    • ASP.NET projects (in any language)
    • VB.NET projects (including ASP.NET VB.NET projects)
  • Extension for created files: defines the extension for files created from the template; value changes according to the item selected in the Only in projects for language drop-down list.
Shorten qualified references

Go to top

Select this check box if you want ReSharper to automatically remove redundant references in method calls for which necessary namespace import directives have been inserted.

 
Reformat

Go to top

Select this check box if you want ReSharper to automatically reformat the deployed template according to your code style settings. If the check box is cleared, ReSharper will only indent the whole template according to the code position where it was deployed, which leaves its formatting unchanged.

 

Template Variables

Item Description Comments
Name

Go to top

In this column, names of template variables are initially displayed in the same order that they appear in the Template text section. You can move them up or down to alter the order in which ReSharper suggests values for variables when the template is applied.


Value

Go to top

In this column, you can view or edit values and/or macros that ReSharper uses to suggest values when deploying the template.

If a value is specified for the first time, this column offers to Choose Macro. Otherwise, it displays a link called Change Macro.

See Choose Macro for details.

Editable Occurrence

Go to top

In this column, you can define whether each template variable will have an associated input field during deployment, and where these input fields should be located.

If a variable appears only once in the template code, this option is expressed by a check box. When this check box is selected, the corresponding field in the resulting code becomes editable.

If a variable appears in the template code n times, this option is expressed by a drop-down box with the following possible choices:

  • Not Editable: input field is not created in the resulting code. The values for the variables suggested by ReSharper (if any) will be inserted by default when deploying the template.
  • #1: allocate the input field at the first occurrence of the template variable.
  • #n: allocate the input filed at the nth occurrence of the template variable.
See Declaring Variables for details.
Move Up / Move Down

Go to top

Define the order of variables in a template by moving the variable rows up and down within the table.

The order of variables specified in the table determines the order in which ReSharper suggests values for variables when the template is applied.


 Tip

To recover the original version of a predefined template after it has been modified, right-click a modified template, and choose Restore Original Version from the drop-down menu.

See Also

Procedures

Reference