Custom Brace formatting with Resharper

C#ResharperIndentationAuto Indent

C# Problem Overview


I'm using Resharper 4.5 and I need custom formatting of braces when writing an array or object initializer. Resharper supports some styles:

Gnu Style:

int[] array = new int[]  
                  {  
                      1, 2, 3  
                  }  

but I need:

int[] array = new int[] 
{  
    1, 2, 3  
}  

Is there any way to customize this templates?

C# Solutions


Solution 1 - C#

You can customize ReSharper to do just that, you'll need to do the following (All in ReSharper -> Options -> C# -> Formatting Style):

  1. In Braces Layout, set Array and object initializer to At Next line (BSD Style).
  2. In Other, make sure that Continuous line indent multiplier is set to 1.
  3. In Other, make sure that Indent array, object and collection initializer block is unchecked.

You should get the style you want.

Solution 2 - C#

As of R#7.1 some Option attributes were changed:

  1. In Braces Layout, set Array and object initializer to At Next line (BSD Style).
  2. In Other, make sure that Continuous line indent multiplier is set to 1.

like in older versions and

  1. In Other, at Align Multiline Constructs make sure that Array, object and collection initializer is unchecked.

Solution 3 - C#

This article seems to have an answer similar to what you're looking for:

ReSharper: Fixing array and object initializer indentation

Solution 4 - C#

(continuation of previous answers by @igal and @mbx)

As of R# 2017.1 (and possibly earlier versions), do the following:

  1. In Formatting Style -> Braces Layout, set Array and object initializer to At Next line (BSD Style)
  2. In Formatting Style -> Other -> Indentation, make sure that Continuous line indent multiplier is set to 1
  3. In Formatting Style -> Other -> Align Multiline Constructs, make sure that Array, object and collection initializer is unchecked. You may also want to uncheck Anonymous method body if that conforms to the same style.

Solution 5 - C#

as far as i know you cant, Resharper comes with predefined styles, but maybe if you create your own live template and set it the way you want it will works.

hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHadi EskandariView Question on Stackoverflow
Solution 1 - C#Igal TabachnikView Answer on Stackoverflow
Solution 2 - C#mbxView Answer on Stackoverflow
Solution 3 - C#Alex BeynensonView Answer on Stackoverflow
Solution 4 - C#cristobalitoView Answer on Stackoverflow
Solution 5 - C#DevManiaView Answer on Stackoverflow