Creating a File Template
File templates are used to create one or more new files with predefined code, such as a type declaration, unit test, etc. File templates have no shortcuts, they are identified by their descriptions. See Creating Files from Templates and Creating Multi-File Templates for details.
The body of a file template consists of literal strings and parameters. The idea is to combine these to maximize efficiency when invoking the template.
To create a new file template
- On the main menu, choose .
- In the Templates Explorer window that appears, click the File Templates tab.
- Optionally, if you want to create your template in a specific settings layer, choose the desired layer in the Layer drop-down list. To learn more, see Storage of Templates.
- Click New Template . The newly created template is opened in the Template Editor.
- Specify template name in the Description field.
- Optionally, in the Default file name specify a name that ReSharper suggests when applying the template. You can also tick the File name must be a valid identifier check box to make ReSharper check if the file name 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 file name with the Current file name without extension macro. You can check the predefined file templates to see how it is implemented.
- To change the default scope of the template, click the Availability hyperlink. In the Select scopes dialog box that appears, use check boxes to define where the new template can be applied. You can expand some scopes to specify details (e.g. file masks or language versions):
Create the body of the template by typing or pasting the desired code.
The template code can contain plain text and parameters. As soon as you type a parameter (for example,
$PARAM$), it appears in the Parameters section to the right of the text area. Configure all defined parameters as described in the Declaring Template Parameters section.
Configure template formatting options:
- Select the Reformat check box to make ReSharper automatically reformats 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 will not insert any namespace import directives.
- To save the template, choose on the Visual Studio menu or press Ctrl+S.