[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
 [Collapse]Coding Assistance
  [Collapse]Code Templates
    Add a Template
    Common Templates
    Members Declaration
    Member Sections
    Interactive Templates
    Templates for Unit Tests
    XPO and XAF Templates
    Templates for LaTeX Formula Creation
    Template Configuration
  [Expand]Auto Completion
  [Expand]Clipboard Tools
  [Expand]Selection Tools
  [Expand]Code Providers
  [Expand]Declare Menu
  [Expand]Typing Helpers
 [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
 [Expand]Extensibility
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Code Templates

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.

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

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.

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.

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

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

or

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

Expanded Template Hints

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

Use the CodeRush | Windows | Training menu item to access the Training Window.

Expanded Learn More About Templates

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