Skip to main content

Code Actions Settings

  • 3 minutes to read

You can configure code actions‘ options on the Editor | C# (Visual Basic) | Code Actions | Code Actions Settings options page.

Page

The Code Actions Settings page contains the following settings:

Allow Converting Not-implemented Properties to Auto-implemented Ones

CodeRush can convert a large number of properties generated by refactoring to auto-implemented properties. This conversion is initially disabled to prevent accidental code change.

To convert not-implemented properties to auto-implemented properties:

The following screencast shows the Convert to Auto-implemented Property (convert all) refactoring.

Allow

Activate a New File When It’s Created by Refactorings (Move Type to File, Declare Class, etc.)

This option specifies whether CodeRush opens a new file created by Move Type to File, Declare Class, and other refactorings. If this option is enabled you can edit the content of a generated file after the refactoring is completed. You can also collect a dropped marker if the Markers feature is enabled to return to the source file. Disable this option, if you want to stay in the source file after a new file is created.

The screencast below shows Move Type to File refactoring that opens the new TestClass file.

Activate

Check Arrays and Collections Length in Code Contracts

This option allows CodeRush to check arrays and collection length in code contracts.

For example, run the Exit.Method contract provider for the following code:

public bool AddRecords(string[] names, object data)
{
    //...
    return true;
}

After execution, this code provider adds the string array length check.

public bool AddRecords(string[] names, object data)
{
    if ((names == null) || (names.Length == 0) || (data == null))
    {
        return false;
    }
    //...
    return true;
}

The Position of Newly-Generated Type Declarations

CodeRush allows you to place generated type declarations in one of the following positions:

  • Above the active type

  • Below the active type

  • Create a new file

Default Body of Newly-Generated Methods

This option allows you to configure the default body of generated methods.

You can set this option to one of the following values:

  • Throw NotImplementedException instance (the default value)

  • Call undeclared method (causes compilation error)

  • Return default value

  • Return default value with TODO comment

When you declare a method in an interface, CodeRush generates the corresponding default body of this method in interface implementers. If you set this option to “Call undeclared method (causes compilation error)” or “Return default value with TODO comment” and call the Declare Method provider, CodeRush declares the method body which reminds you to change this method later.

The following screencast shows the Declare Method provider that declares the “SaveToDB” method in the IPerson interface. The Default Body of Newly-Generated Methods option is set to “Return default value with TODO comment”.

Default Body

Style of Newly-Generated Properties

You can configure style of generated properties.

Available values:

  • Automatic

  • With backing fields

  • Accessors with default body

The screencast below shows the Declare Class provider that generates property accessors with the default body.

Default Body