ReSharper 2017.2 Help

Template Macros

When you apply code templates, ReSharper initializes template parameters with some values. To calculate these values, it uses template macros, which can retrieve a lot of useful data based on the surrounding context, For instance, current file name, current solution name, containing namespace, clipboard content, and so on. Even more, macros can invoke code completion actions, guess and suggest types, variables, tags, and more.

As soon as you declare a new template parameter, the parameter appears in the right part of the Template Editor along with the Choose macro hyperlink below it. Clicking this link allows you to choose a macro for the parameter. When creating a source template macros are specified using the [Macro] attribute. For details, see the full list of template macros.

Some macros just bring you the necessary item. E.g., Current solution name or Suggest tag name. Other macros have their own parameter, which you need to specify. For example, if you choose the Suggest variable of type macro for a template parameter, you will need to provide a type for the corresponding macro parameter. When choosing a macro in the Choose Macro dialog, you can recognize macro parameters by the bold type.

If you do not define any macro for a template parameter, the parameter name is inserted when you apply the template. The user will be suggested to edit this name if the parameter editable.

The best way to grasp the usage of template macros is to study the rich set of ReSharper's predefined templates.

Last modified: 12 October 2017

See Also