Back to Devexpress

Expand Lambda Function

coderushforroslyn-403502-code-style-assistance-code-formatters-expand-lambda-function.md

latest949 B
Original Source

Expand Lambda Function

  • Oct 26, 2021

Expands the lambda function with an expression body onto the lambda function with a block body. You can use this code formatter when you need to extend the code logic in the lambda function and the expression body is not appropriate for this task.

Availability

Available when the caret is in a lambda operator (=>).

Usage

  1. Place the caret in a lambda operator (=>).

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Expand Lambda Function from the menu and press Enter.

After execution, this code formatter expands a single-line lambda function onto a lambda function with a code block body.

csharp
using System;

namespace ConsoleApp {
    public class ExpandLambda {
        Func<string, int> func = s => {
            return s == null ? 0 : s.Length;
        };
    }
}