[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Expand]Unit Testing Assistance
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Collapse]Extensibility
   Adding a Dictionary for the Spell Checker
  [Collapse]Custom Templates Creation
    Adding a Template
    Using Text Commands
    Referencing Namespaces
    Linking Identifiers
    Providing Input Fields
    Using Variables
    Iterating Through Elements
    Template Name Variables
    Alternative Template Expansions
    Text Commands
    String Providers
  [Expand]Context Providers
   Specify a Default Filter for the Jump to Symbol Window
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Template Name Variables

Template Name Variables allow you to define a template with several different expansions. You can include a variable part in the template name and place a text block that depends on the variable value in the template expansion.

Template Name Variables configuration is on the Editor | All Languages | Template Name Variables options page. For instance, the built-in Template Name Variable Type contains system types.

The left side of the page contains Variable Groups. Several groups can separate the values of a single variable with different contexts. The right side contains the name of the variable contained in the selected group, a list of its values, etc.

Note

CodeRush attempts to simplify the variable values after substitution (for instance, the 'System.Boolean' becomes 'bool' in C#) if the checkbox This list holds .NET types is checked.

Expanded Usage

To insert a Template Name Variable into your template, insert the variable name surrounded by the "?" signs into the template name (?variable_name?). To insert the variable value into your expansion, use the Get(variable_name) text command.

A sample type-aware template that uses this Template Name Variable can be defined as follows:

Note

The presented template uses the Field and BlockAnchor text commands. Refer to corresponding articles to learn more about them.

This creates a list of templates with the following names:

  • vib for bool
  • vic for char
  • vid for double
  • vis for string
  • vii for int
  • etc.

Expanded Adding a Template Name Variable

Tip

You can use the code editor's context menu to add a custom type as a Template Name Variable. Right-click the required type and select the Use Type in Templates... item. This adds a fully-qualified type name to the Custom Types group in the Neutral language.

To add a new Template Name Variable, follow the steps below:

  1. Create a new Variable Group using the New Variable Group button to store your variable.

  2. Name the new group.

  3. Fill the Variable Name field, then add name-value pairs to the list. The easiest way to add a list value is to fill the last row and press Enter.

  4. Test your Template Name Variable by creating a template that uses it. See the following example:

    You can now use it as follows:

    • dw1 expands as DayOfWeek.Monday
    • dw2 expands as DayOfWeek.Tuesday
    • etc.

Is this topic helpful?​​​​​​​