Home > Code Generation > CodeRush Standard Templates Library

CodeRush Standard Templates Library

October 23rd, 2012

The standard templates library contains more than one thousand static code templates designed to help you realize any coding requirements. Templates are organized by categories. For instance, there are over 25 root categories for CSharp language on the Templates option page, such as:

  • Attributes
  • Comments
  • Declarations
  • Directives
  • Expressions
  • Graphics
  • Patterns
  • Program Blocks
  • Regions
  • Testing
  • Text
  • WCF
  • etc

Each programming language has its own set of categories and templates. You can import and export the template categories, and add your own categories with custom templates.

With the dynamic lists capability, the number of code templates can total in the tens of thousands. Having learned the template language, it is easy to remember and write code using templates very quickly.

Here are some basic code templates from the library you can start with.

Type Declarations

Type declaration templates make it easy to generate classes, structures, interfaces, enumerations, etc. They are available in the corresponding context (condition), e.g., on an empty line inside a namespace.

Mnemonic Declares
c Class
i Interface
s Struct
d Delegate
e Enumeration
a Abstract class
x Exception class

Member Declarations

Member declaration templates allow you generate new methods, properties, fields and events.

Mnemonic Declares
m Method
p Property
v Variable
ev Event

Note that the ‘v’ template may declare not only fields, but also local variables and parameters depending on the current context. In combination with the dynamic list of standard types, you can specify the desired type of a member using an additional type specification mnemonic:

Mnemonic Type
o object
b Boolean
c Char
i Int32
d Double
s string
u UInt32

Loops and blocks

Code templates for quick generation of loops such as ‘for’, ‘foreach’, ‘while’, ‘do’ and other code blocks like ‘if’, ‘switch’, ‘try/catch’ etc.

Mnemonic Loop or block
f The ‘for’ loop
fe The ‘foreach’ loop
w The ‘while’ loop
dw The ‘do/while’ loop
if The ‘if’ block
sw The ‘switch’ block
tc The ‘try/catch’ block
tcf The ‘try/catch/finally’ block

Returning values

Code templates for generating a return statement with the desired return value.

Mnemonic Return value
rn null
rt true
rf false
r0 zero
r1 one
r-1 -1
rth this
r’ single-quoted character
r” double-quoted string

Note that the ‘r’ template will execute the Smart Return feature. This feature allows you to quickly select the return value from the suggested values (e.g., local variables).

You can see the full collection of code templates for each language on the Templates option page.

Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Oct/23/2012
ID: C207

Similar Posts: