Home > Code Generation, Overview > CodeRush Xpress declaration features

CodeRush Xpress declaration features

July 6th, 2010

CodeRush Xpress includes powerful features to intelligently declare types (classes, structures, interfaces), members, fields, local variables and so much more.

Add Contract

This feature automates the very common task of checking the parameters to a method, to make sure that all have been initialized. Having all the parameter values checked for initialization in one place at the top of the method body results in clearer code . This also allows you to provide a centralized response to invalid parameter values, if needed.

Duplicate Line

To duplicate the line at the caret, press Shift+Enter. If the line qualifies, CodeRush Xpress duplicates the line and may select a portion of the duplicate line for easy modifications.

Consume-first Declaration

The consume-first declaration features of CodeRush Xpress are a quick way to generate the code you need. It starts with a call or a reference to something that doesn’t exist yet (the consumption code).

Declaring Types

To declare a new type, add a reference to it. Usually when you want a new type, you also want a constructor for it. At this point you can press the CodeRush key (Ctrl+`) to declare to declare a class or struct. Here are the consume-first type declarations you get with CodeRush Xpress:

Name Description
Declare Class* Generates a class for the type reference with appropriate constructor.
Declare Delegate* Generates a delegate for the type reference.
Declare Enum Generates an enumeration for the type reference.
Declare Interface* Generates an interface for the type reference.
Declare Struct* Generates a struct for the type reference with appropriate constructor.

Declaring Members

Want to add a member to a type? Just write the code as you would like it to appear. If it’s a method, pass in the parameters you need. Here are the consume-first member declarations you get with CodeRush Xpress:

Name Description
Declare Constructor* Generates a constructor for the selected type object with appropriate parameters.
Declare Enum Element* Generates an enum element for the active element reference.
Declare Event Handler Generates an event handler for the selected method reference with appropriate parameters.
Declare Method* Generates a method for the selected method call with appropriate parameters.
Declare Property Generates a property for the selected element reference.
Declare Property (auto-implemented)* Generates an auto-implemented property for the selected element reference.
Declare Property (with backing field) Generates a property with backing store for the selected element reference.
Declare Getter Generates a getter of the target Property for the selected element reference.
Declare Setter Generates a setter of the target Property for the selected element reference.

Declaring Variables

Declaring variables to represent an expression on a line is easy – just place the caret on a reference to the variable name and press the CodeRush key (Ctrl+`). Than select the declaration you’d like to declare. Here are the consume-first variable declarations you get with CodeRush Xpress:

Name Description
Declare Field* Generates a field variable for the element reference with appropriate type.
Declare Field (read-only)* Generates a read-only field variable for the element reference with appropriate type.
Declare Local Generates a local variable for the element reference with appropriate type.
Declare Local (implicit) Generates an implicit local variable for the element reference.

* Note: feature is not included into CodeRush Xpress in Visual Studio 2010 due to a Microsoft requirement. See the “CodeRush Xpress features differences in Visual studio 2008 and 2010″ post for more info.

—–
Products: CodeRush Xpress
Versions: 12.1 and up
VS IDEs: 2008 and 2010
Updated: Sep/21/2012
ID: C006

Similar Posts: