Get correct indentation in Resharper for object and array initializers

Right now resharper formats our code as follows:

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 was busy with a lot of options, but I don’t seem to understand them. You can help?

+46
c # coding-style formatting visual-studio resharper
Feb 06 '09 at 10:05
source share
4 answers

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

I finally found a way to fix this. Formatting options anonymous methods distributed two separate pages in ReSharper options: Braces and others. β€œDon't put a ridiculous amount” on another page, and β€œIndent the anonymous body method.” Turn off the queue, and set the parameter "At the end of the line", and you get something much nicer:

But I'm not sure about formatting the collection of instance declarations, I'm afraid. :(

+43
Feb 06 '09 at 10:33
source share

I just fought this today. Go to ReSharper \ Options \ Languages ​​\ C # \ Formatting Style \ Other

Scroll to the bottom of the list and uncheck the box "Block initialization of the block, object and collection"

It helped me.

+17
Dec 24 '09 at 16:39
source share

I also had to uncheck the ReSharper \ Options \ Languages ​​\ C # \ Formatting Style \ Other β†’ Align Multiline Constructs checkbox and uncheck the "Array, Object and Collection Initializer" checkbox along with the other answers provided here.

+11
Sep 17 '10 at 9:23
source share

For R # 8, for this purpose, there is a parameter that can be configured in the parameters β†’ Code editing β†’ C # β†’ Formatting style β†’ Bracket layout β†’ Initialization of an array and objects.

"On the next line (BSD style)" is the one requested by this stream.

+1
Jan 30 '15 at 9:23
source share



All Articles