Get correct indentation in Resharper for object and array initializers

后端 未结 4 2097
无人及你
无人及你 2021-02-01 01:25

Right now resharper formats our code like this:

private readonly List folders = new List
                                        {
           


        
相关标签:
4条回答
  • 2021-02-01 01:47

    For R# 8 there is a setting exactly for this purpose in Options -> Code Editing -> C# -> Formatting Style -> Braces Layout -> Array and object initializer.

    "At the next line (BSD style)" is the one which this thread asks for.

    0 讨论(0)
  • 2021-02-01 01:54

    I just had a fight with this today. Go to ReSharper\Options\Languages\C#\Formatting Style\Other

    Scroll to the bottom of the list and uncheck "Indent array, object, and collection initializer block"

    That did the trick for me.

    0 讨论(0)
  • 2021-02-01 01:54

    I also had to uncheck ReSharper\Options\Languages\C#\Formatting Style\Other --> Align Multiline Constructs and uncheck "Array, object and collection initializer" along with the other answers provided here.

    0 讨论(0)
  • 2021-02-01 02:05

    I had the same issue with anonymous delegates. The fix for anonymous delegate formatting is here:

    I did finally find the way to fix this. The options for formatting anonymous methods are spread across two separate pages in ReSharper options: Braces Layout and Other. The “don’t indent a ridiculous amount” is on the Other page, and it’s called “Indent anonymous method body”. Turn it off, and set the brace option to “At end of line”, and you get something much nicer:

    But i'm not sure about the instance declaration collection formatting i'm afraid. :(

    0 讨论(0)
提交回复
热议问题