Roslyn: Issue with object initializers and csharp_new_line_before_open_brace in editorconfig

Created on 16 Oct 2018  路  5Comments  路  Source: dotnet/roslyn

Hi!

I'm using the editorconfig file to fine-tune the coding style settings across multiple visual studio instances. Specifically, I want to configure the placement of the open brace. The csharp_new_line_before_open_brace setting gives me some headache:

When I set

csharp_new_line_before_open_brace = all

I get new lines for Object Initializers like so:

        var foo = new Foo
        {
            Name = "Hello World",
            Id = 0,
        };

When I explicitly specify the individual settings, (which I want, because I'd like to disable specific things like the new line for control statements) like so:

csharp_new_line_before_open_brace = accessors, anonymous_methods, anonymous_types, control_blocks, events, indexers, lambdas, local_functions, methods, object_collection_array_initializers, properties, types

the code formatter produces this (the opening brace is _not_ (!) placed on new line):

        var foo = new Foo {
            Name = "Hello World",
            Id = 0,
        };

Note, I enabled all available values according to https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017#newline).

So, AFAICT this should be the same as "all".

Am I missing something, or is this an issue within VS?

Thanks, david

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/350663/issue-with-object-initializers-and-csharp-new-line.html
VSTS ticketId: 699427_
_These are the original issue comments:_
(no comments)
_These are the original issue solutions:_
(no solutions)

Area-IDE Bug Developer Community Resolution-Fixed

Most helpful comment

I will pick this up and fix it, if it's ok for you?

All 5 comments

I will pick this up and fix it, if it's ok for you?

@Rumpel78 sure thing!

still happening in visual studio professional 2017 15.9.7

@jaroslav-rfe This issue was fixed for the first release of Visual Studio 2019.

Was this page helpful?
0 / 5 - 0 ratings