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.

4
  • 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. Jul 31, 2012 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, 2012 at 16:50
  • Love the xkcd reference. "maybe you will learn to sanitize your sql". Nov 28, 2013 at 9:57

1 Answer 1

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.

6
  • 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: stackoverflow.com/questions/11622581/… Jul 31, 2012 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, 2012 at 21:52
  • @devundef Unfortunately I don't have a clue. But you can always try to ask him twitter.com/fergard/status/228271877393633280 Jul 31, 2012 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, 2019 at 23:11
  • @Mmm Select solution in Solution Explorer, Extensions > ReSharper > Edit > Detect formatting settings to find all of them at once Sep 20, 2019 at 15:16

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.