You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置Rider避免在集合初始化元素间生成"}, {"格式代码?

调整Rider集合初始化的元素换行格式

我需要让Rider在集合初始化时,将元素之间的}, {格式改为逗号后换行、左大括号单独起行的样式。已经检查过Editor→Code Style→Braces Layout和Line Breaks and Wrapping设置,但没找到对应选项。

当前Rider生成的代码

Dictionary<string, string[]> rider = new() {
{
    "first", new[] {
        "a", "b", "c",
        "d", "e", "f"
    }
}, { // ← 不希望的格式
    "first", new[] {
        "a", "b", "c",
        "d", "e", "f"
    }
};

期望的代码格式

Dictionary<string, string[]> rider = new() {
{
    "first", new[] {
        "a", "b", "c",
        "d", "e", "f"
    }
},
{   // ← 期望的格式
    "first", new[] {
        "a", "b", "c",
        "d", "e", "f"
    }
};

当前已查看的设置页面

  • Line Breaks and Wrapping设置页
  • Braces Layout设置页

解决方案

按以下步骤修改设置即可实现期望格式:

  1. 打开Rider设置(快捷键Ctrl+Alt+S)
  2. 导航至Editor → Code Style → C#
  3. 切换到Line Breaks and Wrapping标签页
  4. 向下滚动找到Collection initializers区域
  5. 勾选Place opening brace on new line after comma选项
  6. 点击Apply保存设置,重新格式化代码(快捷键Ctrl+Alt+L)

内容的提问来源于stack exchange,提问作者Charles Burns

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 16:49:54