39

So, this:

cmd = new OdbcCommand( string.Format( @"
SELECT *
  FROM Bobby_Tables
 WHERE Name = {0}", "Little Bobby Drop Tables" ), odbcConnection );

gets formatted to:

cmd = 
      new OdbcCommand( 
            string.Format( 
                  @"
SELECT *
  FROM Bobby_Tables
 WHERE Name = {0}", 
                  "Little Bobby Drop Tables" ), odbcConnection );

I've looked at each of the options for line breaks and wrapping but I haven't been able to find the one to keep things on the same line as long as possible. I'm assuming that I missed the correct option. My Right margin (columns) option is set to 100, which is plenty big.

Question: Is there a way to make it look like the original, and still get smart formatting on other things that actually do need to be wrapped?

I can manually put the

cmd = new OdbcCommand( string.Format (
      @"

back on the first line and it'll leave the verbatim string on the next line happily. That's an alright compromise I guess.

ryancerium
  • 631
  • 1
  • 5
  • 11
  • 1
    Try setting the "Keep existing line breaks" property to true under Code Editing => C# => Formatting Style => Line Breaks and Wrapping. You can also shortten the "Right margin (columns)" property so that the right margin is smaller and thus "Chop if long" doesn't happen as often. – Mike Perrenoud Jul 31 '12 at 16:31
  • Can you elaborate on what you are trying to achieve? Do you want Resharper to bring the Select statement all back into a single line? If so, I don't think it will do that. Resharper is usually trying to reformat code and break it up for readability. – Gambit Jul 31 '12 at 16:50
  • Love the xkcd reference. "maybe you will learn to sanitize your sql". – Casper Leon Nielsen Nov 28 '13 at 09:57
  • Possible duplicate of [How to stop Resharper from line breaking after return keyword for long lines?](http://stackoverflow.com/questions/20509768/how-to-stop-resharper-from-line-breaking-after-return-keyword-for-long-lines) – Michael Freidgeim Feb 23 '16 at 06:04

1 Answers1

90

I guess that your problem is that the first line got broken in three. This is because of bug http://youtrack.jetbrains.com/issue/RSRP-288271 that was fixed in ReSharper 7.0. You should consider upgrading or turning off option ReSharper | Options -> Code Editing | C# | Formatting style | Line breaks and wrapping -> LineWrapping | Wrap long lines.

Dmitry Osinovskiy
  • 9,999
  • 1
  • 47
  • 38
  • Hey @Dmitry Osinovskiy, maybe you have a clue about a problem I'm having with ReSharper 6.1? If you could, please take a look in my question: http://stackoverflow.com/questions/11622581/resharper-unit-test-runner-ignores-deployment-items-configuration – Marcelo De Zen Jul 31 '12 at 17:58
  • We're still on 6.1. I'm using a Right Margin of 100, so it should be plenty. It seems like, "Oh, this new OdbcCommand() is too long, put it on a new line. Oh, this string.Format() is too long, put it on a new line. Oh, this verbatim string is too long, put it on a new line." At least, that's how I imagine the algorithm working. – ryancerium Jul 31 '12 at 21:52
  • @devundef Unfortunately I don't have a clue. But you can always try to ask him https://twitter.com/fergard/status/228271877393633280 – Dmitry Osinovskiy Jul 31 '12 at 23:31
  • As a new user to ReSharper, I'm surprised at how many defaults it has that I disagree with! This was one. Thanks for pointing out how to turn it off. – Mmm Sep 19 '19 at 23:11
  • @Mmm Select solution in Solution Explorer, Extensions > ReSharper > Edit > Detect formatting settings to find all of them at once – Dmitry Osinovskiy Sep 20 '19 at 15:16
  • The option to turn off the wrapping of long lines is now located at ```Extensions > ReSharper> Options > Code Editing > C# > Formatting Style > Line Breaks and Editing > General > Wrap long lines```. Simply un-check the check-box, if it is selected. – CyrilDex Jul 04 '20 at 14:54