Refactorings for Declaration and Initialization
Convert to Initializer
Converts a default constructor call immediately followed by object initialization into an object 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: 
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. 
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. 
Make Implicit
Converts an explicitly-typed variable declaration to an implicit one. 
Move Declaration Near Reference
Moves the declaration statement for a local variable near its first 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. 
Name Anonymous Type
Replaces the anonymous type with a newly-declared 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. 
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. 
|