Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Resharper object initializer indentation as method argument

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.

like image 797
one_mile_run Avatar asked Dec 14 '16 13:12

one_mile_run


1 Answers

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".

like image 82
Neptulon Avatar answered Nov 11 '22 11:11

Neptulon