Home > Code Generation > CodeRush Templates language and learning basics

CodeRush Templates language and learning basics

April 25th, 2012

CodeRush code templates are easy to understand and learn. One of the easiest ways is to dock the CodeRush Training window inside the Visual Studio IDE. This window shows you the available templates for the current context. For example, if the editor caret is inside a namespace, the window will show you the following templates suggestion:

CodeRush Training Window - Type templates

As you see, the first letter (highlighted in red) of the type declaration is used as a template name. If you’d like to declare an interface, you need to type the letter ‘i’ inside a namespace:

CodeRush Code Templates Sample - Interface

This is some kind of a rule for template naming – use abbreviations or mnemonics. In our sample, the first letter of the type is used. If the letter is already used for some template (e.g. “Enum” and “Exception”), the second letter is used to name a template instead.

Here are advanced examples of template names:

  • eaEventArgs
  • ehEventHandler
  • osobject sender

The template name usually sounds like the template expansion. Consider the following examples:

  • rtreturn true:

CodeRush Code Templates Sample - Return True

  • snset null:

CodeRush Code Templates Sample - Set Null

  • inrfif null, return false:

CodeRush Code Templates Sample - If Null Return Zero

  • inr0if null, return zero:

CodeRush Code Templates Sample - If Null Return Zero

CodeRush Constructor Create template
These samples show that the following grammatical structures are common in CodeRush code templates:

  • noun
  • verb noun

Once some templates are used several times, you may acquire a habit to use those ones, because it is one of the fastest ways to write different kind of code blocks. And when you write code fast, you safe your time.

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Oct/02/2012
ID: C159

Similar Posts: