ReSharper 8.0 Web Help

Code templates can adjust to the surrounding context or even act interactively when you apply them. All this is done with template parameters and Template Macros.

You can define and edit template parameters in the Template Editor. As soon as you type a user-defined parameter in the body of a template (for example, $TYPE$), it appears in the Parameters area to the right of the text area, where you can define its behavior by clicking Choose macro:

Declaring_variables_1

You can use any parameter in a template more than once; their values will be synchronized when the template applies.

Note

You cannot edit values of the predefined template parameters ($END$, $SELECTION$, $SELSTART$, and $SELEND$).

To declare a template parameter
  1. Create a new template or open an existing template for editing.
  2. Enter a parameter as $parameter_name$ in the text area of the Template Editor.
  3. To define a macro that calculates parameter value, find the parameter in the Parameters area to the right of the text area and click Choose Macro. If a macro is already defined, you can click its hyperlink to switch to another macro.
  4. In the Choose Macro dialog box that appears, select a macro from the list and click OK. If the selected macro has a parameter, is is displayed in bold in the Choose Macro dialog box (for example, format or type). In this case, after you choose a macro, a text box appears under the parameter. You can specify the macro parameter there.
  5. If you want the parameter to be editable, the Editable check-box next to it should be enabled (which it is by default). Depending on the number of parameter occurrences within the template, do one of the following:
    • If the parameter is used in the template only once, make sure that the check-box is selected.
    • If the parameter is used in the template more than once, a combo box appears, where you can select a sequential number of the editable occurrence. This number specifies to which occurrence of the parameter the input focus will be set when the template is deployed with a Hot Spot Session. You may also notice that the numbers a prefixed with 'M' or other letters. These letters define in which file of a multi-file template the input focus should be set for this parameter. 'M' stays for the main file and appears in all templates.
  6. Optionally, you can select the newly declared parameter in the Parameters area and use up and down arrows to change the order of parameters. The position in the list of parameters defines the order, in which the parameters are switched during the hot spot session when the template is applied. It affects only editable parameters.
  7. To save the template, choose File | Save Selected Items on the Visual Studio menu or press Ctrl+S.