Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper format multiple lines of code to a single line

I often use guard statements to simplify my code and return quickly when an error occurs.

Now I would like to save some space by putting these statements into a single line by selecting the text and hit a key combination.

How can I achieve this?

As example:

  if (!websiteValidationResult.IsSuccess)
  {
      GoToEditView(editWebsiteModel, websiteValidationResult.ErrorMessage);
  }

Format to:

if (!websiteValidationResult.IsSuccess) { GoToEditView(editWebsiteModel, websiteValidationResult.ErrorMessage); }
like image 577
Jamie Avatar asked Sep 03 '25 04:09

Jamie


1 Answers

Yes, you can do this with ReSharper. Go to: Code Editing | C# | Formatting Style | Line Breaks and Wrapping and select Force put on single line for the Break line in a block with a single statement rule.

like image 92
Igal Tabachnik Avatar answered Sep 05 '25 01:09

Igal Tabachnik