20

I have Resharper installed with mainly default settings. Currently, I'd like my multi-line lambda expressions to look something like this:

foobarclass.biz.baz.Event += (s, e) =>
  {
    foo.Bar.DoThings.Whatever();
  };

However, Resharper "helpfully" will reformat my code to be like this:

foobarclass.biz.baz.Event += (s, e) =>
                                 {
                                     foo.Bar.DoThings.Whatever();
                                 };

And in some cases, will also break up long statements so it ends up looking like this:

foobarclass.biz.baz.Event += (s, e) =>
                                 {
                                     foo.
                                        Bar.
                                        DoThings.
                                        Whatever();
                                 };

As you can tell, this auto-formatting makes code a lot less readable. How can I fix this kind of behavior?

Earlz
  • 62,085
  • 98
  • 303
  • 499

1 Answers1

23

Try unchecking:

RESHARPER -> OPTIONS -> C# -> Formatting Style -> Other -> Indent Anonymous Method Body

Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
  • It appears to be a combination of this and changing the braces layout – Earlz Dec 12 '12 at 18:51
  • Though I hate GNU style for most things, for anonymous methods it does what I want – Earlz Dec 12 '12 at 18:52
  • Updated response... this seems to do what you want. – Levi Botelho Dec 12 '12 at 18:52
  • Using Resharper 8 and this option not found anymore. Still suffering from the crazy indentation. Can anyone help? – g.pickardou Nov 09 '13 at 14:31
  • I'll look and get back to you ;) – Levi Botelho Nov 10 '13 at 07:34
  • 6
    @g.pickardou The option is simply called "Anonymous Method Body" now and is located under the "Align Multiline Constructs" header. – Levi Botelho Dec 08 '13 at 17:36
  • The seems to work with the ReSharper (such as when I do Ctrl + K, Ctrl + D, but then if I delete the closing brace and type it again, the indentation is back, so I am wondering if VS is doing it. Everything was working great until I installed VS 2015 and the updated ReSharper... the search continues! – hvaughan3 Aug 27 '16 at 18:03
  • @hvaughan3 I believe that in that case it's VS doing the indentation and not R#. R#'s rules are applied when you do a code cleanup; so if you do that and your code looks good then it's VS causing issues. – Levi Botelho Aug 28 '16 at 17:39
  • That's what I was thinking. Have not been able to figure out which setting in VS it is but will report back when I find the issue. Thanks for getting back to me! – hvaughan3 Aug 28 '16 at 17:50
  • 8
    I know this is an old topic, but I found this because I had the same problem with resharper 2016.2. And changing this setting did nothing, the example code did not even change when ticking and unticking the box. I had to enable the "Use old formatting engine" option under other>other for lambdas to not become massively indented. –  Oct 25 '16 at 06:26
  • 1
    @ErikNilsson: apparently it's a regression: https://youtrack.jetbrains.com/issue/RSRP-460614 – reijerh Nov 07 '16 at 16:25