The requested page is not available for the requested platform. You are viewing the content for Default platform.

Code Templates

  • 3 min to read

CodeRush provides a large library of code templates in C#, VB, JavaScript, TypeScript, and XAML. Templates are easy-to-memorize character sequences that expand into boilerplate code such as class or property definition. Templates help you write code faster.

You can also create a custom template for any code part in C#, VB, JavaScript, TypeScript, XAML, CSS, HTML, and F# languages. See the Add a Template topic for more details on how to create a template from code.

Expand a Template

Type the template name and press Space to expand a template.

For instance, type in "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).

Templates_Main

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).

Wizard

  • Shortcuts... items (available from IDE -> Shortcuts options page).

Wizard

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.

Templates_XAML

Important

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

Type Mnemonic

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.

PSTemplate

Context-Dependent Templates

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.

VSInClass

or

you can create a local variable of type string if a caret is inside a method.

VSInClass

Template Hints

CodeRush allows you to see hints for some of the more common templates in the Training Window.

Templates

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: