CodeRush Pro declaration features
CodeRush Pro includes powerful features to intelligently declare types (classes, structures, interfaces), members, fields, local variables and so much more.
Templates are blocks of code that expand from short abbreviations typed into the code editor. Using code templates decreases code creation time, because it avoids having to type the entire code manually and allows creating regular code sections with only a few keystrokes.
The Smart Constructor templates-based feature allows you to add constructors to the current class or structure, and pass type members, like fields and properties for initialization through its parameters. Creating a constructor is as simple as just typing three keys: “cc & Space”.
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.
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.
The consume-first declaration features of CodeRush Pro 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).
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 Pro:
|Declare Attribute||Generates a new Attribute class for an undeclared attribute.|
|Declare Class||Generates a class for the type reference with appropriate constructor.|
|Declare Class with Properties||Declares a class with properties initialized to the parameters passed to the constructor.|
|Declare Delegate||Generates a delegate for the type reference.|
|Declare Enum||Generates an enumeration for the type reference.|
|Declare EventArgs Descendant||Generates an EventArgs descendant class 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.|
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:
|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||Generates an event member for the selected reference.|
|Declare Event Handler*||Generates an event handler for the selected method reference with appropriate parameters.|
|Declare Initialized Property||Adds an auto-implemented property and initializes it to the parameter at the caret.|
|Declare Initialized Properties||Adds auto-implemented properties and initializes them to each parameter of this constructor.|
|Declare Method*||Generates a method for the selected method call with appropriate parameters.|
|Declare Method (abstract)*||Generates an abstract method for the method call with appropriate parameters.|
|Declare Properties||Generates auto-implemented properties for this object initializer expression.|
|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.|
* Shipped in Refactor! Pro.
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:
|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 Initialized Field||Adds a field and initializes it to the parameter under the caret.|
|Declare Initialized Fields||Adds fields and initializes it to each parameter of this constructor.|
|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.|
|Declare Action||Declares an MVC action.|
|Declare Controller||Declares an MVC controller.|
|Declare View||Declares an MVC view.|