Domanda

What is the best way to prevent ReSharper from wrapping certain lines of code. For example, an if statement with one condition and a simple body should not be wrapped. ReSharper currently forces this line...

if (item == null) { return null;  }

... to break like this:

if (item == null) 
{ 
    return null;  
}

I don't want to blindly disable this feature necessarily... just make it a bit more intelligent.

È stato utile?

Soluzione

Update for newer versions of ReSharper

(my version is 2021.1)

Since a picture is worth than a thousand words, you probably want to configure it like so. In this way it takes care of constructs such as using too:

enter image description here

Check the ones that start with Keep existing arrangement [...] if you want to instruct ReSharper to leave, say, single-line ifs alone if they are already written that way.

Took me longer to figure out than I wanted it to, hopefully it will help someone else.


You can change this in the R# Settings:

  1. Open the menu Resharper -> Options
  2. Go to Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping
  3. Change to option Break line in single embedded statement to Put on a single line or Do not change

Edit: As mentioned by @Alexander it would be more suitable to use the option Break Line in a block with a single statement which I think is available since R# 8

Altri suggerimenti

In latest Resharper it is under General >> "Wrap log lines"

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top