ReSharper 2021.1 Help

Template Types

There are several types of templates that you can use with ReSharper:

  • Live/Surround templates can be used for generating code in existing files and (if there is the $SELECTION$ parameter in the template body) for surrounding code fragments with template code, such as try...catch statement.
    Each live template is identified by a Shortcut— a short string of characters, for example foreach— that you can type right in the editor to invoke the template.

  • Postfix templates, which are available for C#, JavaScript, TypeScript, and C++, help you transform expressions that you have already typed without jumping backwards. For example, you can type .null after an expression and ReSharper will create an if statement that checks the expression to be null. See Postfix Templates for details.

  • Source templates, which are only available for C#, can be created right in the code of your project as extension methods. As soon as you define a source template, you can pick it up in the completion list of corresponding types, similarly to postfix templates. For more information, see Source Templates

  • File templates are used to create one or more new files with predefined code, such as a type declaration, unit test, and so on. File templates have no shortcuts, they are identified by their descriptions. See Create Files from Templates\ and Create Multi-File Templates for details.

Right after installing ReSharper, you will find a lot of predefined templates of all types. Predefined templates cover the most common cases for C#, VB.NET, ASP.NET, XML, HTML, Razor, CSS, JavaScript, TypeScript and Resx code. Predefined templates also include code snippets for C# and JavaScript imported from Visual Studio. Note that imported Visual Studio snippets are a part of ReSharper installation and you cannot import your custom Visual Studio snippets.

For custom cases, ReSharper provides tools for creating, editing, and sharing user-defined code templates that can cover any particular aspect of your development practices.

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NETFeature is available in C++Feature is available in HTMLFeature is available in ASP.NETFeature is available in RazorFeature is available in JavaScriptFeature is available in TypeScriptFeature is available in CSSFeature is available in XMLFeature is available in XAMLFeature is available in Resource filesFeature is available in build script files Feature is not available in Protobuf Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 08 March 2021