Refactoring Assistance
- 3 minutes to read
Refactorings are small changes to working code that improve the internal structure without altering the external behavior of that code.
The Refactorings section describes each refactoring in detail. The description includes the purpose of the refactoring, its availability, and the “how to use” example.
How to Use
Invoke the Code Actions Menu. Place the caret in the part of the code you want to change, for example, on a boolean method parameter, and press Ctrl + . or Ctrl + ~.
CodeRush adds the following items to Visual Studio’s light bulb menu (Code Actions Menu):
- Code Formatters — improve code readability and layout to match a certain style without code behavior change. For example, Sort Namespace References.
- Refactorings — simplify code, improve readability, make code more flexible (for future changes), or bring the code to meet certain standard without code behavior change. For example, Inline Method.
- Code Providers — can change code behavior or declare undeclared types and members. Use them to supplement your code with blocks which you might want to type manually. For example, Create Event Trigger.
Choose the action from the invoked menu. For example, Boolean to Enum.
You can see a preview of the changes CodeRush can apply to your code.
Press Enter to generate code in the selected position.
class TestClass {
private int TestMethod(TestMethodParam a) {
if (a == TestMethodParam.Success)
return 1000;
else
return 1024;
}
}
public enum TestMethodParam {
Success,
Failure
}
CodeRush includes over 60 refactorings you can use to improve C#, Visual Basic, XAML, and Blazor code.
Define Style Rules
You can define a set of programming style rules that CodeRush applies to your code when you refactor. Refer to the Programing Style Rules topic for more information.
Blazor Support
You can apply refactorings from code sections in .razor files.
Note
The refactorings for Blazor are unable to update references in closed .razor files. Make sure all files that may be impacted by a particular refactoring are open in Visual Studio before applying it.