Search code examples
c#-3.0formattingresharper-4.5object-initializers

How to change the formatting of the "Use Object Initializer" refactoring in Resharper?


When I refactor the following line:

Employee e = new Employee();
e.First = "Frank";
e.Last = "Rizzo";

using Resharper's "Use Object Initializer", I get the following:

Employee e = new Employee
             {
                 First = "Frank",
                 Last = "Rizzo"
             };

I really hate this type of formatting because with longer object names and variables it just gets out of control. How can I get Resharper to do the following?

Employee e = new Employee
{
    First = "Frank",
    Last = "Rizzo"
};

Solution

  • You can get very close to what you want in Resharper 4.5.

    Resharper>Options

    Languages>C#>Formatting Style>Other

    under Other uncheck "Indent array, object and collection initializer block."