CodeRush Templates language and learning basics
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:
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:
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:
- ea – EventArgs
- eh – EventHandler
- os – object sender
The template name usually sounds like the template expansion. Consider the following examples:
- rt – return true:
- sn – set null:
- inrf – if null, return false:
- inr0– if null, return zero:
- cc – Create Constructor
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