JetBrains Rider 2024.1 Help

Examples of quick-fixes

Quick-fixes are available in a variety of circumstances, which is too large to be listed. JetBrains Rider provides a total of more than 1200 quick-fixes in all supported languages. Here we will show how to use them using a small selection of situations:

Type mismatch

Whenever the type of an expression cannot be implicitly cast to the type applicable to the expression context, JetBrains Rider detects this error and highlights it in the editor. After placing the caret at the highlighted error and pressing Alt+Enter, you can choose a quick-fix from the following list:

JetBrains Rider: Type mismatch quick-fix

The effects of applying the proposed quick-fixes are illustrated in the table below.

Quick-fix

Effect

Cast to string

JetBrains Rider: Type mismatch quick-fix

Safely cast to string

JetBrains Rider: Type mismatch quick-fix

Change type of o to string

JetBrains Rider: Type mismatch quick-fix

Change type of s to object

JetBrains Rider: Type mismatch quick-fix

Call ToString()

JetBrains Rider: Type mismatch quick-fix

Undefined variable

Whenever JetBrains Rider detects an undefined variable in your code, the error is highlighted. After placing the caret at the highlighted error and pressing Alt+Enter you will be presented with the following list of quick-fixes:

JetBrains Rider: Undefined variable quick-fix

The effects of applying the proposed quick-fixes are illustrated in the table below.

Quick-fix

Effect

Create local variable s

A new local variable s is created proposing you to choose the desired type.

Create parameter s in the containing method

A new parameter is added to the method signature:

JetBrains Rider: Undefined variable quick-fix

Create other

Opens a sub-menu where you can choose to create a field or a property in the corresponding class. For example, if you choose to create a field, a new private field s is created in the current class. The following suggestion appears helping you to choose the correct type of the new field:

JetBrains Rider: Undefined variable quick-fix

Change all s

If you choose Change all, the following suggestion displays:

JetBrains Rider: Undefined variable quick-fix

Type the new name only once; JetBrains Rider changes all the other occurrences of the undefined variable:

JetBrains Rider: Undefined variable quick-fix

Undefined method call

Whenever JetBrains Rider detects a call to an undefined method in your code, the error gets highlighted. After placing the caret at the highlighted error and pressing Alt+Enter, JetBrains Rider displays the following list of quick-fixes:

JetBrains Rider: Undefined method call quick-fix

After applying a quick-fix, the code gets modified as shown in the following table:

Quick-fix

Effect

Create method

This quick-fix declares a new method with the signature derived from the method call, benefiting developers who prefer top-down programming. In our example, JetBrains Rider creates the following declaration, correctly guessing the return type:

JetBrains Rider: Undefined method call quick-fix

JetBrains Rider also suggests applicable types and a name for the parameter of the new method:

JetBrains Rider: Undefined method call quick-fix

Create other

This sub-menu includes other quick-fixes involving creation of auxiliary code. For example:

Create parameter in containing method

This quick-fix creates a new parameter in the current method from the unresolved symbol but doesn't update its base methods or inheritors.

Create parameter in containing method and update hierarchy

This quick-fix creates a new parameter in the current method from the unresolved symbol, and introduces this parameter into any base members and inheritors that the method may have.

Change all

Similarly to the corresponding quick-fix for undefined variables, this quick-fix allows you to quickly replace all occurrences of the symbol someMethod.

Forgotten method return

If a method is expected to return a value but you forgot to provide a return statement, JetBrains Rider warns you about that by highlighting the closing bracket of the troublesome method. After placing the caret at the highlighted error and pressing Alt+Enter you will be presented with the following quick-fixes:

JetBrains Rider: Forgotten method return quick-fix

Quick-fix

Effect

Add return statement

After the quick-fix is applied, JetBrains Rider adds a return statement returning null.

Make method return void

After the quick-fix is applied, JetBrains Rider replaces the initial return type of the method with void.

Missing Using directives

Whenever you have a type name in your code that cannot be resolved because you forgot to write a corresponding using directive in your file, a small popup suggests to import the type:

JetBrains Rider: Namespace import quick-fix

Press Alt+Enter, and the appropriate using directive will be inserted. Should there be multiple types with the matching name, you will be asked to choose the one you wish to use (For more information, refer to Importing Namespaces).

If you chose not to import a required namespace when the popup was displayed, or if you disabled Show the 'Import missing references' popup in editor on the Editor | General | Auto Import page of JetBrains Rider settings Ctrl+Alt+S, you can import a type at any time by placing the caret at the type, pressing Alt+Enter and choosing the corresponding quick-fix.

JetBrains Rider: quick-fixes for missing namespace import

You may want some types or namespaces not to be suggested, for example, if you have something similar to a system type in your solution, say MyFramework.MyCollections.List, but you are not actually using it. To exclude such items from the suggestions, add them to the Exclude from import and completion list on the Editor | General | Auto Import page of JetBrains Rider settings Ctrl+Alt+S.

The format of the entries is Fully.Qualified.Name, Fully.Qualified.Name.Prefix*, or *Fully.Qualified.Name.Suffix. Generic types are specified as List`1.

Missing async modifier

If you have a method that contains the await operator, but that is not defined as asynchronous, JetBrains Rider detects such mismatch and offers to fix this problem using the corresponding quick-fix.

Before:

JetBrains Rider: Missing async modifier quick-fix

Applying the quick-fix:

JetBrains Rider: Missing async modifier quick-fix

After:

JetBrains Rider: Missing async modifier quick-fix

Converting a loop to a LINQ expression

With C# 3.0 and LINQ, developers are able to write data-intensive code more easily by directly describing their intent to the compiler. JetBrains Rider detects code that can be rewritten using LINQ syntax and offers to perform the conversion automatically:

Before:

JetBrains Rider: Converting a loop to a LINQ expression quick-fix

Applying the quick-fix:

JetBrains Rider: Converting a loop to a LINQ expression quick-fix

After:

JetBrains Rider: Converting a loop to a LINQ expression quick-fix

Migrating to IEnumerable in method parameters and returns

JetBrains Rider scans your code base to detect methods that can safely return and accept IEnumerable instead of a more specific type such as Array, List, or ArrayList:

Before:

JetBrains Rider: Migrating to IEnumerable in method parameters and returns

Applying the quick-fix:

JetBrains Rider: Migrating to IEnumerable in method parameters and returns

After:

JetBrains Rider: Migrating to IEnumerable in method parameters and returns

Converting assignment statements to object initializers

JetBrains Rider provides both a context action and a quick-fix to convert assignment statements into object initializers. The context action lets you add field assignments to an initializer one-by-one, whereas the quick-fix adds them all in one go. Here's how the quick-fix works:

Before:

JetBrains Rider: Converting assignment statements to object initializers

Applying the quick-fix:

JetBrains Rider: Converting assignment statements to object initializers

After:

JetBrains Rider: Converting assignment statements to object initializers

Converting static method invocation to extension method call

When you invoke an extension method as a traditional C# static method, JetBrains Rider helps you quickly comply with standard extension method call practices:

Before:

JetBrains Rider: Converting static method invocation to extension method call

Applying the quick-fix:

JetBrains Rider: Converting static method invocation to extension method call

After:

JetBrains Rider: Converting static method invocation to extension method call

Converting anonymous method to lambda expression

JetBrains Rider suggests converting anonymous methods to lambda expressions. The reverse functionality is provided as a context action.

Before:

JetBrains Rider: Converting anonymous method to lambda expression

Applying the quick-fix:

JetBrains Rider: Converting anonymous method to lambda expression

After:

JetBrains Rider: Converting anonymous method to lambda expression

Converting to auto-property

JetBrains Rider makes it quick to convert traditional, private field-based properties to automatic properties implemented in C# 3.0. For more information, refer to Use auto-properties.

Before:

JetBrains Rider: Converting to auto-property

Applying the quick-fix:

JetBrains Rider: Converting to auto-property

After:

JetBrains Rider: Converting to auto-property

Making type parameter invariant

When a usage of a type parameter violates its variance, JetBrains Rider suggests to make the parameter invariant:

Before:

JetBrains Rider: Making type parameter invariant

Applying the quick-fix:

JetBrains Rider: Making type parameter invariant

After:

JetBrains Rider: Making type parameter invariant
Last modified: 11 February 2024