Search code examples
c#jetbrains-iderider

JetBrains Rider: keep single line scope


I press Ctrl+Shift+L in JetBrains Rider, which opens a dialog window. I select Whole Solution, and it starts cleaning up the code. However, I want it to stop transforming this:

public Task<PackageTest?> GetByPackageAndTestIdAsync(Guid packageId, Guid testId) =>
    _context.PackageTests.FirstOrDefaultAsync(p => p.TestId == testId && p.PackageId == packageId);

into this:

public Task<PackageTest?> GetByPackageAndTestIdAsync(Guid packageId, Guid testId)
{
    return _context.PackageTests.FirstOrDefaultAsync(p => p.TestId == testId && p.PackageId == packageId);
}

Solution

  • Try turning off "Apply code body style (expression body vs block body)".

    1. Open Code(menu) -> Reformat and CleanUp
    2. From the 'Select Profile' select the profile that you're using
    3. Click on the edit icon at the top of the left frame.
    4. On the 'Code Cleanup Options' Window turn off 'Apply code body style (expression body vs block body)' in the 'Apply syntax styles' -> 'C#'.