How to fix Resharper object initializer indentation as method argument
Asked Answered
M

3

7

Resharper 2016.2

Current formatting

IEnumerable<Customer> customers = dbCustomers.Select(customer => new Customer
                                                     {
                                                         Name = customer.Name,
                                                         Address = customer.Address,
                                                         Number = customer.Number
                                                     });

Expected formatting

IEnumerable<Customer> customers = dbCustomers.Select(customer => new Customer
{
    Name = customer.Name,
    Address = customer.Address,
    Number = customer.Number
});

Which Resharper 2016.2 configuration can fix that?

Please note, initializer is inside argument brackets, not in variable.

Mahlstick answered 14/12, 2016 at 13:3 Comment(2)
Have you tried this: Options -> Code Editing -> C# -> Formatting Style -> Other -> Align Multiline Constructs -> Array, object and collection initializerAccelerando
@OscarSiauw: Yes, this option is disabled.Mahlstick
M
0

It has just started to work without any changes in R# settings after update to 2016.3 version.

Mahlstick answered 29/12, 2016 at 16:9 Comment(0)
I
1

If still someone needs help with this try this: Resharper Options --> Code Editing --> C# --> Formatting Style --> Other --> Uncheck "Array, object and collection initializer".

Then in: Resharper Options --> Code Editing --> C# --> Formatting Style --> Braces Layout --> "Array and object initializer" = "At next line (BSD Style)".

You could also do this, which makes it a little bit nicer: Resharper Options --> Code Editing --> C# --> Formatting Style --> Line Breaks and Wrappings --> "Wrap object and collection initializer" = "Chop if long or multiline".

Impenetrability answered 22/9, 2017 at 14:0 Comment(0)
I
0

This worked for me. Hope it helps!

Go to Resharper -> Options from Visual Studio menu bar.

On the tree view:

Code Editing -> C# -> Formatting Style -> Braces Layout

On the right panel:

Array and object initializer

  • Expand the options combo box.
  • Pick At the next Line (BSD style) (3rd option).

Formatting style

Isooctane answered 14/12, 2016 at 13:57 Comment(1)
This option is enabled. It does not change the formatting as expected. The problem is, that initializer is inside method arguments list.Mahlstick
M
0

It has just started to work without any changes in R# settings after update to 2016.3 version.

Mahlstick answered 29/12, 2016 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.