Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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 Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Collapse]CodeRush
  System Requirements
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Collapse]Coding Assistance
  [Collapse]Code Templates
    Common Templates
    Members Declaration
    Interactive Templates
    Templates for Unit Tests
    XPO and XAF Templates
    Template Configuration
   Auto Completion (IntelliRush)
   Clipboard Tools
  [Expand]Selection Tools
  [Expand]Code Providers
   Declare Menu
  [Expand]Typing Helpers
   Naming Assistant
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
  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

Code Templates

Code Templates allow you to insert boilerplate code sections instead of entering the code manually.

CodeRush is shipped with a large library of code templates. To expand a template, type the template name and press Space. For instance, to create a simple class, type in "c" and press Space. This creates a new class and prompts you to name it (the constructor is named automatically). You can also expand templates with the Tab key by binding the "TemplateExpand" command to it using the Setup Wizard or Shortcuts... items in the CodeRush menu.

Important

The default CodeRush configuration does not interfere Visual Studio features such as IntelliSense. This prevents the Space and Tab keys from expanding templates because this key confirms the IntelliSense suggestion by default. The default configuration allows you to expand a template only if you close the IntelliSense suggestions window by pressing Esc before the Space key. You can also force the templates to expand in the IDE | IntelliSense options page.

Code templates are context-aware which means a shortcut expands different templates depending on the context. For instance, the "mb" template declares a Boolean method inside a class or generates a call to MessageBox.Show() inside a method.

Code templates are combinable, for example, you can combine the "r" (for return) template with the "t" (for true) templates and use the "rt" template to insert the return true statement. The same principle is used to declare typed members and variables: you can add a type mnemonic to each member or variable template to make it expand to the correct type.

Expanded Adding a Template

You can create a template from code using the code editor's context menu:

  • Select the code to create a template from
  • Right-click the selection and choose Selection to Template...

  • Enter the template name that corresponds to its mnemonics. You should type the template name in your code to expand the template.

  • Select the template's category. Right-click a category to add a new one.
  • Use OK to confirm the template's creation. This opens the new template in the Template Editor.
  • Make the required changes to your new template, and click OK to close the Template Editor.
  • Test the created template by expanding it as described above.

Refer to the Template Configuration article for details on how to edit existing templates and define the new ones manually.

Expanded See Also

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