简体   繁体   English

Visual Studio / ReSharper:如何在params之前用逗号包装长行?

[英]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. 我一直在使用ReSharper自定义我的格式化需求以进行代码清理。 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. 我还没弄明白怎么做的一件事是如何让params / fields / list项包含引导逗号而不是尾随逗号。

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"
};

(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: 但是,C#允许您在最后一个元素之后放置逗号,因此所有行看起来都相同:

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

Seems you can do this in Resharper 2017 似乎你可以在2017年的Resharper中做到这一点

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

I asked JetBrains the same question. 我问JetBrains同样的问题。 And they said that it is not possible in ReSharper 5 or 6. 他们说在ReSharper 5或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 . 如果您希望新的ReSharper具有该功能,您可以试试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM