Get correct indentation in Resharper for object and array initializers
Asked Answered
N

4

46

Right now resharper formats our code like this:

private readonly List<Folder> folders = new List<Folder>
                                        {
                                            new Folder()
                                        };

but I want it to look like this:

private readonly List<Folder> folders = new List<Folder>
{
    new Folder()
};

I've been messing with the options a lot, but can't seem to get them right. Can you help?

Nicholle answered 6/2, 2009 at 10:5 Comment(2)
related: #747851Exactly
Clearly and objectively the only sane layout </troll>Wishful
J
43

I had the same issue with anonymous delegates. The fix for anonymous delegate formatting is here:

I did finally find the way to fix this. The options for formatting anonymous methods are spread across two separate pages in ReSharper options: Braces Layout and Other. The “don’t indent a ridiculous amount” is on the Other page, and it’s called “Indent anonymous method body”. Turn it off, and set the brace option to “At end of line”, and you get something much nicer:

But i'm not sure about the instance declaration collection formatting i'm afraid. :(

Jit answered 6/2, 2009 at 10:33 Comment(1)
Oh man I accidentally logged in under a new account and can't log in! I would totally accept this answer otherwise! - HarryIzettaizhevsk
P
17

I just had a fight with this today. Go to ReSharper\Options\Languages\C#\Formatting Style\Other

Scroll to the bottom of the list and uncheck "Indent array, object, and collection initializer block"

That did the trick for me.

Palatial answered 24/12, 2009 at 16:39 Comment(1)
Partially solved this problem for me. I say partially because there still is some indentation left, although not that much (4 spaces to be more precise). +1.Borchardt
F
11

I also had to uncheck ReSharper\Options\Languages\C#\Formatting Style\Other --> Align Multiline Constructs and uncheck "Array, object and collection initializer" along with the other answers provided here.

Faery answered 17/9, 2010 at 9:23 Comment(0)
D
1

For R# 8 there is a setting exactly for this purpose in Options -> Code Editing -> C# -> Formatting Style -> Braces Layout -> Array and object initializer.

"At the next line (BSD style)" is the one which this thread asks for.

Deport answered 30/1, 2015 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.