Visual Studio/ReSharper: How to wrap long lines with commas before params?
Asked Answered
J

3

10

I've been customizing my formatting desires using ReSharper for code clean-up. So far I've been able to make the clean-up rules match my coding style within:
     ReSharper -> Options -> Languages -> C# -> Formatting Style

One thing I haven't figured out how to do yet is how to have params/fields/list items wrap with leading commas instead of trailing commas.

Example of what I want:

var list = new List<string> {
    "apple"
    , "banana"
    , "orange"
};

Example of what I get currently:

var list = new List<string> {
    "apple",
    "banana",
    "orange"
};
Jive answered 16/9, 2010 at 14:47 Comment(0)
C
3

(Not an answer, but this doesn't fit in a comment.)

The reason why some people prefer leading commas to trailing commas is because then it's not the last line that is slightly different from all the others, but the first one. This makes it neater to add new elements at the end.

However, C# allows you to place a comma even after the last element, so all lines look the same:

var list = new List<string> {
    "apple",
    "banana",
    "orange",
};
Cowbane answered 16/9, 2010 at 14:54 Comment(2)
Thank you for the comment. I fault my own example - I should have given the following: private void ExampleMethod(string pArg1, bool pArg2, int pArg3) { ... } .... or perhaps: var foo = string.Format("{0}{1}{2}", var1, var2, var3);Jive
I liked leading leading commas as they allow commenting out or removal of any single line with having to change a line next to it. now I know c# ignores the last comma i may have to change that approach. Thanks for the info and well worth posting ;-)Piacular
H
1

I asked JetBrains the same question. And they said that it is not possible in ReSharper 5 or 6.

I think I will just need to change my style a little bit then.

If you want the new ReSharper to have that capability, you can try this.

Headwater answered 24/6, 2011 at 13:40 Comment(0)
V
1

Seems you can do this in Resharper 2017

https://youtrack.jetbrains.com/issue/RSRP-380962#u=1485456634915

Vermiculate answered 26/2, 2017 at 0:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.