- 3 minutes to read
Expand a Template
Type a template name and press Space to expand the template.
For instance, type "c" and press Space to create a simple class in C#. This creates a new class and prompts you to name it (CodeRush names the constructor automatically).
You can also expand templates with the Tab key.
Use one of the following ways to bind the "TemplateExpand" command to the Tab key:
- The Setup Wizard (available from the CodeRush -> Setup Wizard... options menu).
- Shortcuts... items (available from IDE -> Shortcuts options page).
The example below shows how to expand the "g3x2" template with the Tab key in XAML to create a grid with three columns and two rows.
The default CodeRush configuration does not interfere with Visual Studio features such as IntelliSense. IntelliSense prevents the Space or Tab key from expanding templates because this key confirms the IntelliSense suggestion. You should press Esc to close the IntelliSense suggestions window and then press Space to expand a template. You can also force the templates to expand in the IDE | IntelliSense options page.
Expand Templates in Blazor
C# templates can be expanded from @code sections in .razor files.
CodeRush declares dependent namespaces when corresponding templates are expanded. For example, the "nsb" template adds the using System.Text namespace reference to the top of a .razor file.
Code templates allow you to declare typed members and variables. For example, you can add a type mnemonic to each member template or variable template to make it expand to the correct type. The screencast below shows how to expand the "ps" template to create a string type property.
CodeRush expands different templates depending on the context. For instance, you can use the "vs" template to create a string type member variable if the caret is inside a class.
you can create a local variable of type string if a caret is inside a method.
CodeRush shows hints for some of the more common templates in the Training Window.
Use the CodeRush | Windows | Training menu item to access the Training Window.
Learn More About Templates
You can find more information on templates in the following topics:
- Common Templates
- Interactive Templates
- Member Sections
- Members Declaration
- Templates for Unit Tests
- XPO and XAF Templates
- Templates for Blazor
- Templates for DevExpress Blazor Controls
- Templates for HTML
- Templates for LaTeX Formula Creation
- Create a Template for a Selected Code
- How to: Create a Template from Scratch
- How to: Create a Template from an Existing One
- Export and Import Templates
- Template Configuration