ReSharper Web Help

Code templates can adjust to the surrounding context when they are applied. They can even act interactively if they are parameterized. All this is done with Template Variables.

You can define and edit template variables in the Template Editor. As soon as you type a user-defined variable in the body of a template (for example, $VAR$), it appears in the right part of the Template Editor:

Any particular variable may appear in a template more than once.

 Note

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

To declare a template variable
  1. Create a new template or open an existing template for editing.
  2. Enter a variable as $variable_name$ in the text area of the Template Editor.
  3. To define a value of the variable, find it in the right part of the Template Editor and click Choose Macro. If a macro is already defined, click Change Macro 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 does not contain references, proceed to step 6.
  5. If the selected macro contains parameters, they are displayed in bold (for example, format or type). In this case, a link highlighted in red will appear in the Value column next to the variable. Click the link to specify the parameter value. See Choose Macro for details.
  6. If you want that variable to become a template parameter, the Editable Occurrence should be enabled. Depending on the number of variable occurrences within the template, do one of the following:
    • If the variable appears in the template only once, select or deselect the check box.
    • If the variable appears in the template more than once, the combo box appears, where you can select a sequential number of the editable occurrence. This number specifies to what occurrence of the variable the input focus will be set when the template is applied.
  7. Optionally, click Move Up or Move Down to define the order that ReSharper will use to suggest input fields when a parameterized template is applied. This order affects only variables with the enabled occurrence.
  8. To save changes, choose File | Save Selected Items on the Visual Studio menu or press Ctrl+S.

See Also

Concepts

Procedures

Reference

External Links