Back to Devexpress

Code Actions Settings

coderushforroslyn-401767-configuration-options-code-actions-settings.md

latest5.3 KB
Original Source

Code Actions Settings

  • Apr 15, 2022
  • 3 minutes to read

You can configure code actions ‘ options on the Editor | C# (Visual Basic) | Code Actions | Code Actions Settings options 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.

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.

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:

csharp
public bool AddRecords(string[] names, object data)
{
    //...
    return true;
}
vb
Public Function AddRecords(ByVal names As String(), ByVal data As Object) as Boolean
    '...
    Return True
End Function

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

csharp
public bool AddRecords(string[] names, object data)
{
    if ((names == null) || (names.Length == 0) || (data == null))
    {
        return false;
    }
    //...
    return true;
}
vb
Public Function AddRecords(ByVal names As String(), ByVal data As Object) As Boolean
    If names Is Nothing OrElse names.Length = 0 OrElse data Is Nothing Then
        Return False
    End If
    '...
    Return True
End Function

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

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.