JetBrains Rider 2023.2 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.

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.

List of template macros

The table below lists all macros that are available for variables in .NET-specific templates.

The Expression column lists macro expressions that can be used in source templates, for example, [Macro(Target = "myVariable", Expression = "suggestVariableName()")]

The Description column lists macros as they are displayed in the Choose Macro dialog when you create or edit template variables in the user interface.

Expression

Description

Details

guessElementType()

Guess element type of collection represented by variable

Analyzes code and guesses type of element of a collection.

Macro parameters:

  • variable - reference to another parameter in the template

suggestIndexVariable()

Suggest name for an index variable

Suggests a unique name for an index variable at the evaluation point

    getAlphaNumericFileNameWithoutExtension()

    Current file name without extension and with all non-alphanumeric characters replaced with underscores

    Evaluates to the current file name without extension and with all non-alphanumeric characters replaced with underscores

      getAlphaNumericMainFileNameWithoutExtension()

      Name of the primary file without extension with all non-alphanumeric characters replaced with underscores

      Evaluates to the primary file name without extension and with all non-alphanumeric characters replaced with underscores

        arrayVariable()

        Suggest an array variable

        Suggests a variable whose type is an array type

          fixedTypeName()

          Insert reference to type

          Evaluates to the selected type name

          Macro parameters:

          • type - type

          capitalize()

          Value of another variable with the first letter in uppercase

          Capitalizes string value (i.e. changes the case of the first letter to uppercase)

          Macro parameters:

          • another variable - reference to another parameter in the template

          clipboard()

          Clipboard content

          Evaluates to the current textual clipboard content

            complete()

            Execute basic completion

            Shows basic code completion list at the point where the variable is evaluated

              completeSmart()

              Execute smart completion

              Shows smart code completion list at the point where the variable is evaluated

                completeType()

                Execute type completion

                Shows type completion list at the point where the variable is evaluated

                  constant()

                  Constant value

                  Evaluates to the specified constant value

                  Macro parameters:

                  • Constant value - text string

                  typeMember()

                  Containing type member name

                  Evaluates to the short name of the most inner containing type member (e.g. method or property)

                    typeName()

                    Containing type name

                    Evaluates to the short name of the most inner containing type

                      typeRef()

                      Containing type reference

                      Evaluates to the reference of the most inner containing type

                        context()

                        List of items describing current context

                        Provides a list of items describing current context. This includes file name, containing type name, namespace name, etc.

                          getCreationTime()

                          Date and time when the file was created in specified format

                          Evaluates to file creation date and time of the current file

                          Macro parameters:

                          • format - text string

                          getCurrentDate()

                          Current date in specified format

                          Evaluates to the current date

                          Macro parameters:

                          • format - text string

                          getCurrentTime()

                          Current date and time in specified format

                          Evaluates to the current date and time

                          Macro parameters:

                          • format - text string

                          getCurrentNamespace()

                          Containing namespace

                          Evaluates to the name of the containing namespace

                            decapitalize()

                            Value of another variable with the first character in lowercase

                            Decapitalizes string value (i.e. changes the case of the first letter to lowercase)

                            Macro parameters:

                            • another variable - reference to another parameter in the template

                            getDefaultNamespace()

                            Default namespace

                            Evaluates to the default namespace for the current project

                              fileDefaultNamespace()

                              Default namespace for current file

                              Evaluates to the default namespace for the current file

                                getFileName()

                                Current file name

                                Evaluates to the current file name

                                  getFileNameWithoutExtension()

                                  Current file name without extension

                                  Evaluates to the current file name without extension

                                    getFullUserName()

                                    Full user name of the current user

                                    Evaluates to the full name of the current user

                                      guessExpectedElementType()

                                      Guess element type for expected collection type

                                      Guesses the element type if a collection type is expected at this point

                                        guessExpectedType()

                                        Guess type expected at this point

                                        Guesses the type expected at this point

                                          guid()

                                          New GUID

                                          Generates a new Globally Unique Identifier (GUID)

                                            lineNumber()

                                            Current line number

                                            Evaluates to number of the line where the macro is evaluated

                                              list()

                                              Comma-delimited list of values

                                              Displays the specified list of values in the completion list

                                              Macro parameters:

                                              • Comma-delimited list of values - text string

                                              To add the comma (,) as a value to the list, escape it with the backslash (\).

                                              getOutputName()

                                              Current project output assembly name

                                              Evaluates to the output assembly name for the current project

                                                parameterOfType()

                                                Suggest parameter of type

                                                Suggests parameters of the specified type

                                                Macro parameters:

                                                • type - type

                                                getProjectName()

                                                Name of the current project

                                                Evaluates to the current project name

                                                  getSolutionName()

                                                  Current solution name

                                                  Evaluates to the current solution name

                                                    spacestounderstrokes()

                                                    Value of another variable, where spaces will be replaced with '_'

                                                    Changes spaces to underscores (i.e. 'do something useful' becomes 'do_something_useful')

                                                    Macro parameters:

                                                    • another variable - reference to another parameter in the template

                                                    enumerableVariable()

                                                    Suggest enumerable variable

                                                    Suggests a visible variable that can be enumerated (that is, used in a foreach loop as collection)

                                                      suggestVariableName()

                                                      Suggest name for a variable

                                                      When executed in a variable declaration (where variable name should stand), suggests a name for the variable

                                                        variableOfType()

                                                        Suggest variable of type

                                                        Suggests variables of the specified type

                                                        Macro parameters:

                                                        • type - type

                                                        suggestVariableType()

                                                        Suggest type for a new variable

                                                        Suggests a type for a new variable declared in the template

                                                          getUpperCaseAlphaNumericFileName()

                                                          Current file name in uppercase with all non-alphanumeric characters replaced with underscores

                                                          Evaluates to the current file name in uppercase with all non-alphanumeric characters replaced with underscores

                                                            getUserName()

                                                            Short name of the current user

                                                            Evaluates to the current username

                                                              nameOfEntity()

                                                              Name of entity

                                                              Evaluates to 'nameof(entity)' if possible or 'entity' otherwise

                                                                dependencyPropertyType()

                                                                DependencyProperty type

                                                                Evaluates to dependency property type specific to the current framework

                                                                  fullTagName()

                                                                  Full tag name

                                                                  Inserts the full name of the containing tag

                                                                    suggestXmlAttributeNameByTag()

                                                                    Suggest XML attribute name by tag

                                                                    Suggests XML attribute name used in the same tags in the current document

                                                                      suggestAttributeName()

                                                                      Suggest XML attribute name

                                                                      Suggests XML attribute name used in the current document

                                                                        suggestXmlTagName()

                                                                        Suggest XML tag name

                                                                        Suggests XML tag name used in the current document

                                                                          tagName()

                                                                          Tag name

                                                                          Inserts the name of the containing tag without namespace

                                                                            tagNamespace()

                                                                            Tag namespace

                                                                            Inserts the namespace of the containing tag

                                                                              castToLeftSideType()

                                                                              Cast to the required type (if the cast is necessary)

                                                                              Inserts (if required) a cast to the type which is expected at the left side of the assignment expression

                                                                                fileheader()

                                                                                File header

                                                                                Inserts the file header specified in settings

                                                                                  TestSubject()

                                                                                  Test Subject

                                                                                  Inserts the type of the class for which tests are generated

                                                                                    suggestAttributeNameByTag()

                                                                                    Suggest attribute name by tag

                                                                                    Suggests an attribute name used in the same tags in the current document

                                                                                      suggestAttributeValue()

                                                                                      Suggest attribute value

                                                                                      Suggests an attribute value for the current HTML tag attribute

                                                                                        suggestTagName()

                                                                                        Suggest tag name

                                                                                        Suggests a tag name used in the current document

                                                                                          AspMasterpageContentGenerator()

                                                                                          ASP.NET Masterpage content generator

                                                                                          Generates content for masterpage content placeholders at the point where the variable is evaluated

                                                                                            AspMvcAction()

                                                                                            ASP.NET MVC Action

                                                                                            Shows completion list with available ASP.NET MVC Actions at the point where the variable is evaluated

                                                                                              AspMvcController()

                                                                                              ASP.NET MVC Controller

                                                                                              Shows completion list with available ASP.NET MVC Controllers at the point where the variable is evaluated

                                                                                                runAtServer()

                                                                                                Insert runat="server" if server-side tag selected

                                                                                                Inserts runat="server" if a server-side tag selected

                                                                                                  constTypeName()

                                                                                                  Containing type name with const

                                                                                                  Evaluates to the short name of the most inner containing type with a const specifier

                                                                                                    cppFunctionParameterList()

                                                                                                    Containing function parameter list

                                                                                                    Evaluates to a comma-separated list of the parameter names of the containing function

                                                                                                      cppFunctionParameter()

                                                                                                      Documentation: function parameter type with name

                                                                                                      Duplicates the containing template line for each function parameter and evaluates to the parameter type with name

                                                                                                        cppFunctionParameterName()

                                                                                                        Documentation: function parameter name

                                                                                                        Duplicates the containing template line for each function parameter and evaluates to the parameter name

                                                                                                          cppFunctionParameterType()

                                                                                                          Documentation: function parameter type

                                                                                                          Duplicates the containing template line for each function parameter and evaluates to the parameter type

                                                                                                            cppFunctionReturnValue()

                                                                                                            Documentation: function return value

                                                                                                            Keeps the containing template line only if the function return type is non-void

                                                                                                              cppTemplateParameterName()

                                                                                                              Documentation: template parameter name

                                                                                                              Duplicates the containing template line for each template parameter and evaluates to the template parameter name

                                                                                                                cppMacroParameterName()

                                                                                                                Documentation: macro parameter name

                                                                                                                Duplicates the containing template line for each macro parameter and evaluates to the macro parameter name

                                                                                                                  cppFunctionReturnType()

                                                                                                                  Documentation: function return type

                                                                                                                  Evaluates to the function return type

                                                                                                                    cppEntityShortName()

                                                                                                                    Documentation: entity short name

                                                                                                                    Evaluates to the short name of the entity that is being documented

                                                                                                                      cppEntityQualifiedName()

                                                                                                                      Documentation: entity qualified name

                                                                                                                      Evaluates to the qualified name of the entity that is being documented

                                                                                                                        cppEnumToStringEnumerator()

                                                                                                                        Enum to string: enumerator name

                                                                                                                        Duplicates the containing template line for each enumerator and evaluates to the name of the enumerator

                                                                                                                          cppEnumToStringEnumeratorName()

                                                                                                                          Enum to string: enumerator name as a string

                                                                                                                          Duplicates the containing template line for each enumerator and evaluates to a string with the name of the enumerator

                                                                                                                            cppEnumToStringEnum()

                                                                                                                            Enum to string: enum name

                                                                                                                            The name of the enum that the action is invoked on

                                                                                                                              cppExpandableTemplateNewline()

                                                                                                                              Newline in the documentation and enum-to-string templates

                                                                                                                              Evaluates to a newline in the documentation and enum-to-string templates

                                                                                                                                cppFileheader()

                                                                                                                                File header (C++)

                                                                                                                                Inserts the file header specified in settings

                                                                                                                                  cppPchIncludeDirective()

                                                                                                                                  Precompiled header file include directive

                                                                                                                                  Evaluates to an include directive for the precompiled header file or to an empty string if the project does not use precompiled headers

                                                                                                                                    substituteUnrealMacro()

                                                                                                                                    Substitute Unreal template macros

                                                                                                                                    Substitutes Unreal template macros

                                                                                                                                      Last modified: 21 September 2022