JetBrains Rider 2021.1 Help

Template Macros

When you apply code templates, JetBrains Rider 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 filename, 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 Edit variables dialog, where you can also 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. For example, 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.

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 JetBrains Rider's predefined templates.

Last modified: 08 March 2021