CodeRush Xpress

Refactorings for Declaration and Initialization

 

Convert to Initializer

Converts a default constructor call immediately followed by object initialization into an object initializer.

Refactoring - Convert to Initializer

Decompose Initializer

Converts an object initializer to a default constructor call followed by object initialization. Available when the caret is on type reference in the constructor call.

Before:

[C#]

MediaPlayerPro mediaPlayerPro = new MediaPlayerPro { NumColumns = 3, StartingFolder = @"C:\Images" };

After:

Refactoring - Decompose Initializer

Note the variable name is linked up after decomposing the initializer, allowing for a quick rename if desired.

Make Explicit

Converts an implicitly-typed local variable to a variable with an explicit type.

Refactoring - Make Explicit

Make Explicit (and Name Anonymous Type)

Converts an implicitly-typed local variable to a variable with an explicit type, creates a named type to represent the expression on the right, and replaces the anonymous type with a newly-declared type. Other anonymous types in this project having the same shape will also be replaced by the new type.

Refactoring - Make Explicit (and Name Anonymous Type)

Make Implicit

Converts an explicitly-typed variable declaration to an implicit one.

Refactoring - Make Implicit

Move Declaration Near Reference

Moves the declaration statement for a local variable near its first reference.

Refactoring - Move Declaration Near Reference

This refactoring is sometimes useful in preparing a block of code for Extract Method (if a selected block contains the variable declaration, the variable won't need to be passed in as a input parameter).

Move Initialization to Declaration

Combines a local variable's declaration with its first initialization.

Refactoring - Move Initialization to Declaration

Name Anonymous Type

Replaces the anonymous type with a newly-declared type.

Name Anonymous Type

Additionally, other anonymous types in this project having the same shape (matching property names of the same types) will be replaced by the new type. For example, watch what happens when you apply this refactoring the first anonymous type assigned to the variable superCar1 below:

Before:

[C#]

var superCar1 = new { MaxSpeed = 250, Driver = "Speed" };
var superCar2 = new { MaxSpeed = 250, Driver = "Racer X" };

After:

[C#]

var superCar1 = new SuperCar(250, "Speed");
var superCar2 = new SuperCar(250, "Racer X");

The anonymous type assigned to superCar2 is also replaced by the new type.

Remove Assignments to Parameter

Removes assignments to value parameters, declaring a new local at the first assignment.

Remove Assignments to Parameter

Split Initialization from Declaration

Breaks an initialized declaration for a local variable into a declaration and a separate initialization statement.

Before:

[C#]

string[] files = System.IO.Directory.GetFiles(_StartingFolder);

After:

[C#]

string[] files;
files = System.IO.Directory.GetFiles(_StartingFolder);

Split Temporary Variable

Splits a local variable which has too many assignments, declaring a new local at the first new assignment following the first reference. In this example where the local variable "i" has multiple assignments and references, the preview hint shows a new variable named "splitI" will be introduced, and all subsequent references to "i" will be replaced with the new splitI variable.

Refactoring - Split Temporary Variable

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.