Question

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.

Was it helpful?

Solution

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

enter image description here

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top