Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
};
like image 790
soslo Avatar asked Sep 16 '10 14:09

soslo


2 Answers

(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",
};
like image 156
dtb Avatar answered Sep 24 '22 13:09

dtb


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.

like image 22
kimsk Avatar answered Sep 22 '22 13:09

kimsk