ReSharper Web Help

ReSharper | Tools | Create Live Template from Selection

With ReSharper, you can create live templates based on a fragment of your source code. ReSharper automatically converts some fields into template parameters.

To create a live template from a code fragment
  1. In the editor, select a block of code to create a template from.
  2. On the main menu, choose ReSharper | Tools | Create Live Template from Selection.
  3. In the Select Fields and Context for New Template dialog box that appears, ReSharper suggests a draft for a new template and automatically converts some fields into template parameters:
    Templates__Select_Fields_for_New_Template
  4. If the template parameters section contains any entries, you can check where they are used and what they replace in the Template text area.
  5. If you think that some parameters are unnecessary, you can deselect them so that the original code is used instead. As you select or deselect parameters, the Template text view changes accordingly. If you are unsure whether to use the suggested template parameters or not, study the Template Parameters section. Also, you will be able to introduce other parameters into the created template in the next steps.
  6. In the Context drop-down list, select the scope where the new template will be applicable.
  7. Click Create and Edit.
  8. The new template will be opened in the Template Editor so you can proceed with its creation as described in the Creating a Template section.

Tip

Templates from source code are saved in 'This computer' settings layer. If necessary, you can share it later by copying to a team-shared settings layer or by exporting it into a file. It might be also useful to study the way ReSharper stores templates.


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available

Tip

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