質問

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.

役に立ちましたか?

解決

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

enter image description here

他のヒント

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top