Automatic Code Generation
Code templates are blocks of code that expand from short abbreviations and mnemonics that you type into the editor.
CodeRush's template engine represents the state-of-the-art in code template technology, offering unrivaled and unparalleled flexibility and power.
To expand a template, type in the template name and then press Space. Many templates start out simple, but can be made more and more
specific with additional modifying mnemonics that you can chain together into a powerful template combo! For example, you can type "m" to declare
a void method (or Sub in VB), or "mb" to declare a method that returns a Boolean, or "mb[" to declare a method that returns an array of Booleans.
As you see it's very easy to learn templates because of the strong logic and common sense in their structure.
One more thing that makes templates a joy to use is their ability to adapt to context and expand in an intelligent manner; the same template can
expand appropriately for different contexts. For instance, you can use the same "mb" alias to declare a Boolean method if you're inside a class, or to
invoke a message box if you're inside a method. Context allows templates to use the simplest possible abbreviation in both cases. So instead of having
to memorize thousands of crazy abbreviations, you simply learn one or two rules and apply a bit of common sense, and you'll find yourself up and running in no time.
One of the coolest features in CodeRush is the training window, which displays useful hints as well as template verbs so you can be instantly productive.
In addition to these hints, the training window presents a template expansion preview. Using this preview you can see the code that will be generated if you press
Space to expand the template.
To see a sample template expansion, click the image below.
Templates can do more than simply enter text. They can also position the caret, select code, drop markers (for navigation), create text fields or establish links
among identifiers (so changes to one result in changes to all). All these are little enhancements work together so you can write code more efficiently and devote more
focus to the design and the essence of the problem you're trying to solve. Read on to learn more about these powerful tools you can incorporate into your own templates...
CodeRush includes dozens of Code Providers used to create common code parts based on existing code. The major code providers relate to automatic declaration. They enable
you to create a declaration based on a reference to an undeclared class, member, variable, struct etc. In addition, there are conversion code providers, code providers working with
loops and conditionals, embedding code providers etc.
The CodeRush context menu contains only code providers available in the current context.
Here is the full list of currently available code providers:
Supported Code Providers
Cycle Scope Up/Down
You can change the scope of a class or a class member with a single keystroke. Use the ALT+UP or ALT+DOWN shortcuts to change the element scope.
Duplicate Line is useful when you need to create several similar lines in your code. For instance, you are going to declare a number of string fields. You can declare each field manually,
but that will take too much time. The other method is to create a single declaration, and duplicate it with Duplicate Line. Place the cursor on the line to be duplicated,
and press SHIFT+ENTER. CodeRush will duplicate the line and select the field name in the new line, that will allow you to immediately type the name of the new field.
CodeRush includes the following duplications:
|Field||Duplicates a field declaration.
|Initialized Field||Duplicates an initialized field declaration (bringing the initialization to the new line).
|Initialized Integer Field||Duplicates integer fields initialized to an integer value. The initialized value is incremented by one for the duplicated line.
|Event||Duplicates event declarations.
|Method (Interface)||Duplicates method declarations when inside an interface.
|Property (Interface)||Duplicates property declarations when inside an interface.
|Using||Duplicates using statements.
|if (aa is bb)||
Matches if-expressions checking to see if object ooo is of type ttt="". Declares a new local variable of type ttt,
initialized to ooo (typecast as ttt).
|Assignment Statement||Duplicates an assignment statement.
|Flagged Enum Element||Duplicates an initialized element of an enumeration, doubling the initialized value on the next line.
Intellassist completes text at the caret with an in-scope identifier, and may include other suggestions.
To use Intellassist, just write code as you normally would. When Intellassist senses one or more suggestions matching the code you've entered so far,
the best suggestion will be displayed to the right of the caret. You can accept the offered suggestion, or its part (to the next uppercase letter) by pressing ENTER or
If more than one entry is suggested, you can cycle forward and backward through the suggestions by pressing the TAB and SHIFT+TAB.
Smart Constructor enables you to add a constructor to an existing class in several keystrokes. In addition, the generated constructor includes initialization of the specified members.
An XML documentation stub is generated as well.
To add a constructor to a class just type "cc" within the class body and press Space. If the class contains members, Smart Constructor
offers you to choose the ones to be initialized.
Smart Parens And Brackets
Smart Parens & Brackets adds a closing paren or bracket, after the opening one is typed, and places a text field between them.
The feature is activated if an opening parenthesis or bracket is typed at the end of a an identifier, or if a parenthesis is typed in front of it.
The feature also enables you to quickly enclose an identifier to parens. Just select the needed identifier or another part of code, and
type the opening paren.