Skip to main content
A newer version of this page is available. .

Code Providers

  • 3 minutes to read

CodeRush ships with over 40 Code Providers that can generate a lot of code for you: declare class, declare property, declare method; add a getter/setter accessor to a property, add missing constructors; add the implementation of IDisposable, ISerializable, IComparable or IEquatable interfaces, and more. This simplifies and speeds up the code creation process.

The topics in the Code Providers section describe each code provider in detail. The description includes the purpose of the code provider, 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, and press Ctrl + . or Ctrl + ~.

    ActionsMenu

    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.
  2. Choose the action from the invoked menu. For example, Declare Field with Initializer.

    You can see a preview of the changes CodeRush can apply to your code. Code_Generation_Main

  3. Press Enter to perform the action.

    The red target picker appears in Declaration Providers. This picker allows you to choose the place where the generated code can be inserted.

    TargetPicker

    You can configure which Declaration Provider should invoke the target picker in the Editor | All Languages | Code Actions | Target Picker options page.

    TargetPickerOptions

  4. Use the Up Arrow and Down Arrow keys to move the target picker.

  5. Press Enter to generate code in the selected position. For example, the Declare Field with Initializer code provider adds the initialized field declaration to the current class and assigns the parameter value to it.

int iD;
bool DeleteRecord(int ID) {
    iD = ID;
    // ...
    return true;
}

You can run most code providers in C#, and Visual Basic. The Declare Local provider also supports TypeScript and JavaScript. The Import Type/All Types code provider supports XAML.

Blazor Support

You can apply Exit Method Contract, Throw Exceptions Contract, Introduce Format Item, and Add Else Statement code providers from code sections in .razor files.

ActionsMenu

NOTE

The code providers for Blazor are unable to update references in closed .razor files. Make sure all files that may be impacted by a particular code provider are open in Visual Studio before applying it.