Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper 7.1 object initializer formatting

When doing something like this:

MyObject tmp = new MyObject();
tmp.Prop = "Hello";

ReSharper tells me to 'Use object initializer', so I let it reformat the code, and I get something like this:

MyObject tmp = new MyObject {
                                Prop = "Hello"
                            };

However, I would like the first brace to be on the second line, like this:

MyObject tmp = new MyObject 
                            {
                                Prop = "Hello"
                            };

But I can't find any setting for this anywhere. I have the setting 'C# -> Formatting Style -> Braces Layout -> Array and object initializer' set to 'At next line (BSD style)'

Could there be some other setting interfering with this, preventing the formatting I want?

Edit: If I manually format the code like I want it, it will automatically reformat (to the wrong format) when I enter the semi colon.

like image 203
Joel Avatar asked Feb 08 '13 07:02

Joel


2 Answers

So I finally found the setting that was messing with the formatting:

enter image description here

like image 114
Joel Avatar answered Sep 17 '22 19:09

Joel


Sometimes i need to set the same option in VS and Resharper.

In Resharper it's like you said:

C# -> Formatting Style -> Braces Layout -> Array and object initializer' set to 'At next line (BSD style)

In Visual Studio:

Tools -> Options... -> Text Editor -> C# -> Formatting -> New Lines -> Place open brace on new line for object initialzers
like image 42
Malmi Avatar answered Sep 18 '22 19:09

Malmi