JetBrains Rider 2026.3 Help

用于 C# 的 EditorConfig 属性:大括号布局

此页面列出了自定义 JetBrains Rider EditorConfig 属性 ,您可以使用这些属性来配置 C# 的格式化偏好,特别是 JetBrains Rider 在生成新代码和 重新格式化现有代码时如何排列大括号;尤其是,在 如果 或 for 运算符之后有多种放置大括号的方式。

大括号布局

类型和命名空间声明

属性名称:

[resharper_]csharp_类型_声明_大括号、 [resharper_]csharp_brace_style、 [resharper_]类型_声明_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

namespace N { interface I { void foo(); } class C { } }

行尾无空格

namespace N{ interface I{ void foo(); } class C{ } }

下一行

namespace N { interface I { void foo(); } class C { } }

下一行缩进

namespace N { interface I { void foo(); } class C { } }

下一行缩进 2

namespace N { interface I { void foo(); } class C { } }

pico

namespace N { interface I { void foo(); } class C { } }

在命名空间声明中缩进

属性名称:

[resharper_]csharp_命名空间_内_缩进, [resharper_]命名空间_内_缩进

可能的值:

true | false

示例:

真

namespace N { interface I { void foo(); } class C { } }

false

namespace N { interface I { void foo(); } class C { } }

方法声明

属性名称:

[resharper_]csharp_可调用_声明_大括号、 [resharper_]csharp_brace_style、 [resharper_]可调用_声明_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

class C { void Method() { foo(); foo1(); } }

行尾无空格

class C { void Method(){ foo(); foo1(); } }

下一行

class C { void Method() { foo(); foo1(); } }

下一行缩进

class C { void Method() { foo(); foo1(); } }

下一行缩进 2

class C { void Method() { foo(); foo1(); } }

pico

class C { void Method() { foo(); foo1(); } }

lambda 和委托(匿名方法声明)

属性名称:

[resharper_]csharp_匿名_方法_声明_大括号、 [resharper_]csharp_brace_style、 [resharper_]匿名_方法_声明_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

D d = delegate() { int x = 0; return x; }

行尾无空格

D d = delegate(){ int x = 0; return x; }

下一行

D d = delegate() { int x = 0; return x; }

下一行缩进

D d = delegate() { int x = 0; return x; }

下一行缩进 2

D d = delegate() { int x = 0; return x; }

pico

D d = delegate() { int x = 0; return x; }

属性声明

属性名称:

[resharper_]csharp_访问器_所有者_声明_大括号、 [resharper_]csharp_brace_style、 [resharper_]访问器_所有者_声明_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

class C { int Property { get { return null; } set { } } }

行尾无空格

class C { int Property{ get { return null; } set { } } }

下一行

class C { int Property { get { return null; } set { } } }

下一行缩进

class C { int Property { get { return null; } set { } } }

下一行缩进 2

class C { int Property { get { return null; } set { } } }

pico

class C { int Property { get { return null; } set { } } }

访问器声明

属性名称:

[resharper_]csharp_访问器_声明_大括号、 [resharper_]csharp_brace_style、 [resharper_]访问器_声明_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

行尾无空格

class C { int Property { get{ return null; } set{ Notify(value); Set(value); } } }

下一行

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

下一行缩进

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

下一行缩进 2

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

pico

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

'case' 标签下的块

属性名称:

[resharper_]csharp_case_块_大括号、 [resharper_]csharp_brace_style、 [resharper_]case_块_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

switch (expression) { case 0: { foo(); break; } }

行尾无空格

switch (expression) { case 0:{ foo(); break; } }

下一行

switch (expression) { case 0: { foo(); break; } }

下一行缩进

switch (expression) { case 0: { foo(); break; } }

下一行缩进 2

switch (expression) { case 0: { foo(); break; } }

pico

switch (expression) { case 0: { foo(); break; } }

表达式(初始值设定项、switch 表达式、模式、集合表达式)

属性名称:

[resharper_]csharp_初始值设定项_大括号、 [resharper_]csharp_brace_style、 [resharper_]初始值设定项_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

int[] array = new int[] { 1, 2, 3 }

行尾无空格

int[] array = new int[]{ 1, 2, 3 }

下一行

int[] array = new int[] { 1, 2, 3 }

下一行缩进

int[] array = new int[] { 1, 2, 3 }

下一行缩进 2

int[] array = new int[] { 1, 2, 3 }

pico

int[] array = new int[] { 1, 2, 3 }

在表达式大括号内使用连续行缩进

属性名称:

[resharper_]csharp_使用_初始值设定项_大括号_内_连续_缩进, [resharper_]使用_初始值设定项_大括号_内_连续_缩进

可能的值:

true | false

示例:

真

int[] array = new int[] { 1, 2, 3 }

false

int[] array = new int[] { 1, 2, 3 }

其他

属性名称:

[resharper_]csharp_其他_大括号、 [resharper_]csharp_brace_style、 [resharper_]其他_大括号、 [resharper_]brace_style

可能的值:

  • 行尾 :行尾(K&R 风格)

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

  • 下一行缩进 :下一行缩进(Whitesmiths 风格)

  • 下一行缩进 2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

行尾

if (condition) { foo(); } else { foo(); }

行尾无空格

if (condition){ foo(); } else{ foo(); }

下一行

if (condition) { foo(); } else { foo(); }

下一行缩进

if (condition) { foo(); } else { foo(); }

下一行缩进 2

if (condition) { foo(); } else { foo(); }

pico

if (condition) { foo(); } else { foo(); }

允许在 '{' 后添加注释

属性名称:

[resharper_]csharp_允许_左大括号_后_注释, [resharper_]允许_左大括号_后_注释

可能的值:

true | false

示例:

真

if (condition) { // comment statement; }

false

if (condition) { // comment statement; }

空大括号格式设置

属性名称:

[resharper_]csharp_空_块_样式, [resharper_]空_块_样式

可能的值:

  • 多行 :在不同的行上

  • 一起 :将大括号放在一起

  • 同一行一起 :在同一行上放在一起

示例:

多行

class C { void EmptyMethod() { } }

一起

class C { void EmptyMethod() { } }

同一行一起

class C { void EmptyMethod() { } }
2026年 11月 10日