如何设置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设置页
解决方案
按以下步骤修改设置即可实现期望格式:
- 打开Rider设置(快捷键
Ctrl+Alt+S) - 导航至
Editor → Code Style → C# - 切换到
Line Breaks and Wrapping标签页 - 向下滚动找到Collection initializers区域
- 勾选Place opening brace on new line after comma选项
- 点击
Apply保存设置,重新格式化代码(快捷键Ctrl+Alt+L)
内容的提问来源于stack exchange,提问作者Charles Burns
相关产品推荐
相关产品推荐

