Visual Studio/ReSharper:如何在参数之前用逗号换行长行?

发布于 2024-09-19 22:23:17 字数 451 浏览 4 评论 0原文

我一直在使用 ReSharper 进行代码清理来自定义我的格式化需求。到目前为止,我已经能够使清理规则与我的编码风格相匹配:
    ReSharper ->选项->语言 -> C#->格式化样式

我还没弄清楚如何做的一件事是如何让参数/字段/列表项用前导逗号而不是尾随逗号括起来。

我想要的示例:

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

我当前得到的示例:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听闻余生 2024-09-26 22:23:17

(不是答案,但这不适合评论。)

有些人更喜欢前导逗号而不是尾随逗号的原因是因为最后一行与所有其他行略有不同,但是第一个。这使得在末尾添加新元素变得更加整洁。

但是,C# 甚至允许您在最后一个元素之后放置逗号,因此所有行看起来都相同:

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:

var list = new List<string> {
    "apple",
    "banana",
    "orange",
};
兮子 2024-09-26 22:23:17

我向 JetBrains 询问了同样的问题。他们说这在 ReSharper 5 或 6 中是不可能的。

我想我只需要稍微改变一下我的风格。

如果您希望新的 ReSharper 具有该功能,您可以尝试

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文