Back to Devexpress

Refactoring Assistance

coderushforroslyn-115806-refactoring-assistance.md

latest21.9 KB
Original Source

Refactoring Assistance

  • Dec 10, 2021
  • 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

  1. 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 + ~.

  2. Choose the action from the invoked menu. For example, Boolean to Enum.

  3. Press Enter to generate code in the selected position.

csharp
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.

RefactoringC#VBRazorXAML
Boolean to Enum
Combine/Split Conditional(s)
Compress to/Expand Null Coalescing Operation
Compress to/Expand Ternary Expression
Compress/Expand Assignment
Conditional to Switch/Switch to Conditional
Convert Nested Element to Attribute/Attribute to Nested Element
Convert to Auto-Implemented Property
Convert to Constant
Convert to Math.Pow Call
Convert to Property with Backing Field
Convert to String Interpolation
Convert to System Type/Built-In Type
Convert to Tuple
Convert to Initializer/Decompose Initializer
Declare Event Handler (Razor)
Declare Partial Class Part/Partial Record Part
Decompose Parameter
Discard Variable
Extract Interface
Extract String to Resource
Flatten Conditional
ForEach to For/For to ForEach
ForEach to Linq
Import Missing Namespaces
Inline Lambda
Inline Method
Inline Method and Delete
Inline Temp
Introduce Using Statement
Make Implicit/Explicit
Make Read-Only
Move Declaration Near Reference
Move Initialization to Declaration
Move to Code Behind
Move File to Folder
Move Type to File
Move All Types to Files
Move Type to Namespace
Name Anonymous Type
Optimize Namespace References
Promote to Generic Parameter
Pull Member Up
Remove Discard Variable
Remove Variable
Remove Variable with its Initializer
Remove Redundant Assignment
Remove Redundant Constructor
Remove Redundant Delegate Creation
Remove Redundant Destructor
Remove Redundant Type Qualifier
Remove Type Qualifier
Remove Unused Member
Remove Unused Parameter
Remove Unused Type
Rename
Rename File to Match Type
Rename Namespace to Match Folder Structure
Rename Type to Match File
Reorder Parameters
Reverse Boolean
Reverse Conditional
Simplify Expression
Split Initialization from Declaration
Split String
Use Environment.NewLine
Use Expression Body
Use NameOf
Use String.Compare
Use String.Format
Use String.IsNullOrEmpty
Use String Builder
Widen Scope
Widen Scope (Promote to Field)
RefactoringC#VBRazorXAML

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.

See Also

How to: Repeat Last Refactoring