Search code examples
formattingresharperobject-literal

ReSharper formatting of complex object literals


When I have complex object literals, ReSharper insists on formatting them with a very liberal use of newlines. For instance, the example below is a formatted example from my code; note how even angle brackets and parenthesis are placed on lines of their own.

var myResultItem = new ResultItem
 {
   Investigation =
       new List<Investigation>
       {
           new Investigation
           {
              Id
                =
                  new List
                  <
                  CV
                  >
                    {
                        MyEnum
                          .MyValue
                          .AsCV
                           (
                           )
                     }
                  }
             },
             Item =
                 new TextResult
                     {
                      TextResultValue =
                                 "Some text"                                 
                     }
             };

I have tried various R# options, but I have been unable to find what setting it is that triggers this behavior.

For less complex literals, as well as most other code, the formatting looks good.

I'm using ReSharper 8.2 in VS 2013.


Solution

  • Try unchecking ReSharper | Options | Code Editing | C# | Formatting Style | Other | Align Multiline Constructs | Array, object and collection initializer. Also try increasing a value of ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Right margin.