JetBrains Rider 2025.2 Help

EditorConfig 属性(适用于 C#):空行

此页面列出了自定义 JetBrains Rider EditorConfig 属性 ,您可以使用这些属性来配置 C# 中的格式化首选项,具体来说,JetBrains Rider 是否应增加或减少命名空间、成员、区域和导入指令组周围的空行数。

常规

区域周围

属性名称:

[resharper_]csharp_blank_lines_around_region[resharper_]blank_lines_around_region

可能的值:

整数

示例:

值:0

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

值:1

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

值:2

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

区域内

属性名称:

[resharper_]csharp_blank_lines_inside_region[resharper_]blank_lines_inside_region

可能的值:

整数

示例:

值:0

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

值:1

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

值:2

abstract class C { protected abstract void Method1(); #region Region Description protected abstract void Method2(); #endregion protected abstract void Method3(); }

单行注释前

属性名称:

[resharper_]csharp_blank_lines_before_single_line_comment[resharper_]blank_lines_before_single_line_comment

可能的值:

整数

示例:

值:0

void Foo() { var x = 5; // comment Call(); ////CommentedCall(); }

值:1

void Foo() { var x = 5; // comment Call(); ////CommentedCall(); }

值:2

void Foo() { var x = 5; // comment Call(); ////CommentedCall(); }

声明中的空行

保留声明中的最大空行

属性名称:

[resharper_]csharp_keep_blank_lines_in_declarations[resharper_]keep_blank_lines_in_declarations

可能的值:

整数

示例:

格式化之前

格式化后,值:0

class C { void Method1() {} void Method1() {} }
class C { void Method1() { } void Method1() { } }

格式化之前

格式化后,值:1

class C { void Method1() {} void Method1() {} }
class C { void Method1() { } void Method1() { } }

格式化之前

格式化后,值:2

class C { void Method1() {} void Method1() {} }
class C { void Method1() { } void Method1() { } }

移除声明中 '{' 之后和 '}' 之前的空行

属性名称:

[resharper_]csharp_remove_blank_lines_near_braces_in_declarations[resharper_]remove_blank_lines_near_braces_in_declarations

可能的值:

true | false

示例:

格式化之前

格式化之后,真

class C { void Method1() {} void Method1() {} }
class C { void Method1() { } void Method1() { } }

格式化之前

格式化之后,假

class C { void Method1() {} void Method1() {} }
class C { void Method1() { } void Method1() { } }

文件头注释后

属性名称:

[resharper_]csharp_blank_lines_after_start_comment[resharper_]blank_lines_after_start_comment

可能的值:

整数

示例:

值:0

// Header text class A { }

值:1

// Header text class A { }

值:2

// Header text class A { }

不同的 'using' 组之间

属性名称:

[resharper_]csharp_blank_lines_between_using_groups[resharper_]blank_lines_between_using_groups

可能的值:

整数

示例:

值:0

using System; using System.Collections; using myNamespace;

值:1

using System; using System.Collections; using myNamespace;

值:2

using System; using System.Collections; using myNamespace;

'using' 列表后

属性名称:

[resharper_]csharp_blank_lines_after_using_list[resharper_]blank_lines_after_using_list

可能的值:

整数

示例:

值:0

using System; namespace N { }

值:1

using System; namespace N { }

值:2

using System; namespace N { }

命名空间周围

属性名称:

[resharper_]csharp_blank_lines_around_namespace[resharper_]blank_lines_around_namespace

可能的值:

整数

示例:

值:0

namespace N1 { } namespace N2 { }

值:1

namespace N1 { } namespace N2 { }

值:2

namespace N1 { } namespace N2 { }

命名空间内部

属性名称:

[resharper_]csharp_blank_lines_inside_namespace[resharper_]blank_lines_inside_namespace

可能的值:

整数

示例:

值:0

namespace N1 { class C1 { } class C2 { } }

值:1

namespace N1 { class C1 { } class C2 { } }

值:2

namespace N1 { class C1 { } class C2 { } }

文件作用域的命名空间指令后

属性名称:

[resharper_]csharp_blank_lines_after_file_scoped_namespace_directive[resharper_]blank_lines_after_file_scoped_namespace_directive

可能的值:

整数

示例:

值:0

namespace N1; class C1 { } class C2 { }

值:1

namespace N1; class C1 { } class C2 { }

值:2

namespace N1; class C1 { } class C2 { }

类型周围

属性名称:

[resharper_]csharp_blank_lines_around_type[resharper_]blank_lines_around_type

可能的值:

整数

示例:

值:0

class C1 { int a; } class C2 { int a; } class C3 { int a; }

值:1

class C1 { int a; } class C2 { int a; } class C3 { int a; }

值:2

class C1 { int a; } class C2 { int a; } class C3 { int a; }

单行类型周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_type[resharper_]blank_lines_around_single_line_type

可能的值:

整数

示例:

值:0

delegate int MyDelegate(int a); delegate int MyDelegate2(int a); delegate int MyDelegate3(int a);

值:1

delegate int MyDelegate(int a); delegate int MyDelegate2(int a); delegate int MyDelegate3(int a);

值:2

delegate int MyDelegate(int a); delegate int MyDelegate2(int a); delegate int MyDelegate3(int a);

类型内部

属性名称:

[resharper_]csharp_blank_lines_inside_type[resharper_]blank_lines_inside_type

可能的值:

整数

示例:

值:0

class C { int x; int y; }

值:1

class C { int x; int y; }

值:2

class C { int x; int y; }

字段周围

属性名称:

[resharper_]csharp_blank_lines_around_field[resharper_]blank_lines_around_field

可能的值:

整数

示例:

值:0

class C { /// <summary>x description</summary> int x; /// <summary>y description</summary> int y; }

值:1

class C { /// <summary>x description</summary> int x; /// <summary>y description</summary> int y; }

值:2

class C { /// <summary>x description</summary> int x; /// <summary>y description</summary> int y; }

单行字段周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_field[resharper_]blank_lines_around_single_line_field

可能的值:

整数

示例:

值:0

class C { int x; int y; }

值:1

class C { int x; int y; }

值:2

class C { int x; int y; }

属性/事件周围

属性名称:

[resharper_]csharp_blank_lines_around_property[resharper_]blank_lines_around_property

可能的值:

整数

示例:

值:0

class C { /// <summary>x description</summary> public int X { get { return 1; } } /// <summary>y description</summary> public int Y { get { return 2; } } }

值:1

class C { /// <summary>x description</summary> public int X { get { return 1; } } /// <summary>y description</summary> public int Y { get { return 2; } } }

值:2

class C { /// <summary>x description</summary> public int X { get { return 1; } } /// <summary>y description</summary> public int Y { get { return 2; } } }

单行属性/事件周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_property[resharper_]blank_lines_around_single_line_property

可能的值:

整数

示例:

值:0

class C { public int X { get { return 1; } } public int Y { get { return 2; } } }

值:1

class C { public int X { get { return 1; } } public int Y { get { return 2; } } }

值:2

class C { public int X { get { return 1; } } public int Y { get { return 2; } } }

auto/abstract 属性/事件周围

属性名称:

[resharper_]csharp_blank_lines_around_auto_property[resharper_]blank_lines_around_auto_property

可能的值:

整数

示例:

值:0

class C { /// <summary>x description</summary> public int X { get; set; } /// <summary>x description</summary> public int Y { get; set; } }

值:1

class C { /// <summary>x description</summary> public int X { get; set; } /// <summary>x description</summary> public int Y { get; set; } }

值:2

class C { /// <summary>x description</summary> public int X { get; set; } /// <summary>x description</summary> public int Y { get; set; } }

单行 auto/abstract 属性/事件周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_auto_property[resharper_]blank_lines_around_single_line_auto_property

可能的值:

整数

示例:

值:0

class C { public int X { get; set; } public int Y { get; set; } }

值:1

class C { public int X { get; set; } public int Y { get; set; } }

值:2

class C { public int X { get; set; } public int Y { get; set; } }

属性/事件访问器周围

属性名称:

[resharper_]csharp_blank_lines_around_accessor[resharper_]blank_lines_around_accessor

可能的值:

整数

示例:

值:0

class C { public int X { get { DoSomething(); return 1; } set { DoSomething(); myField = value; } } }

值:1

class C { public int X { get { DoSomething(); return 1; } set { DoSomething(); myField = value; } } }

值:2

class C { public int X { get { DoSomething(); return 1; } set { DoSomething(); myField = value; } } }

单行属性/事件访问器周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_accessor[resharper_]blank_lines_around_single_line_accessor

可能的值:

整数

示例:

值:0

class C { public int X { get { return 1; } set { myField = value; } } }

值:1

class C { public int X { get { return 1; } set { myField = value; } } }

值:2

class C { public int X { get { return 1; } set { myField = value; } } }

方法周围

属性名称:

[resharper_]csharp_blank_lines_around_invocable[resharper_]blank_lines_around_invocable

可能的值:

整数

示例:

值:0

class C { void Method1() { foo(); foo2(); } void Method2() { foo(); foo2(); } }

值:1

class C { void Method1() { foo(); foo2(); } void Method2() { foo(); foo2(); } }

值:2

class C { void Method1() { foo(); foo2(); } void Method2() { foo(); foo2(); } }

单行方法周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_invocable[resharper_]blank_lines_around_single_line_invocable

可能的值:

整数

示例:

值:0

abstract class C { abstract void Method1(); abstract void Method2(); }

值:1

abstract class C { abstract void Method1(); abstract void Method2(); }

值:2

abstract class C { abstract void Method1(); abstract void Method2(); }

代码中的空行

保留代码中的最大空行

属性名称:

[resharper_]csharp_keep_blank_lines_in_code[resharper_]keep_blank_lines_in_code

可能的值:

整数

示例:

格式化之前

格式化后,值:0

void Method() { foo(); foo(); }
void Method() { foo(); foo(); }

格式化之前

格式化后,值:1

void Method() { foo(); foo(); }
void Method() { foo(); foo(); }

格式化之前

格式化后,值:2

void Method() { foo(); foo(); }
void Method() { foo(); foo(); }

移除代码中 '{' 之后和 '}' 之前的空行

属性名称:

[resharper_]csharp_remove_blank_lines_near_braces_in_code[resharper_]remove_blank_lines_near_braces_in_code

可能的值:

true | false

示例:

格式化之前

格式化之后,真

void Method() { foo(); foo(); }
void Method() { foo(); foo(); }

格式化之前

格式化之后,假

void Method() { foo(); foo(); }
void Method() { foo(); foo(); }

局部函数周围

属性名称:

[resharper_]csharp_blank_lines_around_local_method[resharper_]blank_lines_around_local_method

可能的值:

整数

示例:

值:0

void Method() { void LocalFunction1() { foo(); foo2(); } void LocalFunction2() { foo(); foo2(); } }

值:1

void Method() { void LocalFunction1() { foo(); foo2(); } void LocalFunction2() { foo(); foo2(); } }

值:2

void Method() { void LocalFunction1() { foo(); foo2(); } void LocalFunction2() { foo(); foo2(); } }

单行局部函数周围

属性名称:

[resharper_]csharp_blank_lines_around_single_line_local_method[resharper_]blank_lines_around_single_line_local_method

可能的值:

整数

示例:

值:0

void Method() { void LocalFunction1() { } void LocalFunction2() { } }

值:1

void Method() { void LocalFunction1() { } void LocalFunction2() { } }

值:2

void Method() { void LocalFunction1() { } void LocalFunction2() { } }

带控制传输的语句前

属性名称:

[resharper_]csharp_blank_lines_before_control_transfer_statements[resharper_]blank_lines_before_control_transfer_statements

可能的值:

整数

示例:

值:0

void Foo(string arg) { Logger.Log("Foo"); if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

值:1

void Foo(string arg) { Logger.Log("Foo"); if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

值:2

void Foo(string arg) { Logger.Log("Foo"); if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

带控制传输的语句后

属性名称:

[resharper_]csharp_blank_lines_after_control_transfer_statements[resharper_]blank_lines_after_control_transfer_statements

可能的值:

整数

示例:

值:0

void Foo(string arg) { if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

值:1

void Foo(string arg) { if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

值:2

void Foo(string arg) { if (arg == null) throw new ArgumentNullException(); var smth = arg.GetSomething(); if (smth == null) return null; var smthElse = smth.GetSomethingElse(); }

带子块的语句前

属性名称:

[resharper_]csharp_blank_lines_before_block_statements[resharper_]blank_lines_before_block_statements

可能的值:

整数

示例:

值:0

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

值:1

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

值:2

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

带子块的语句后

属性名称:

[resharper_]csharp_blank_lines_after_block_statements[resharper_]blank_lines_after_block_statements

可能的值:

整数

示例:

值:0

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

值:1

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

值:2

string Foo(string arg) { Logger.Log("Foo"); if (arg == "A") { DoSomething(); DoSomethingElse(); } DoMoreThings(); }

多行语句前

属性名称:

[resharper_]csharp_blank_lines_before_multiline_statements[resharper_]blank_lines_before_multiline_statements

可能的值:

整数

示例:

值:0

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

值:1

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

值:2

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

多行语句后

属性名称:

[resharper_]csharp_blank_lines_after_multiline_statements[resharper_]blank_lines_after_multiline_statements

可能的值:

整数

示例:

值:0

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

值:1

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

值:2

string Foo(string arg) { DoSomething(); foreach (var x in y) { x.DoSomething(); x.DoSomethingElse(); } DoSomething(); foreach (var x in y) x.DoSomething(); DoSomething(); DoSomething( 1, 2); DoSomething(); }

switch 语句中带有块的 'case' 部分周围

属性名称:

[resharper_]csharp_blank_lines_around_block_case_section[resharper_]blank_lines_around_block_case_section

可能的值:

整数

示例:

值:0

switch (a) { case 1: { DoThis(); DoThat(); break; } case 2: { DoIt(); DoItAgainWithLove(); break; } default: { DoNothing(); DoSomething(); break; } }

值:1

switch (a) { case 1: { DoThis(); DoThat(); break; } case 2: { DoIt(); DoItAgainWithLove(); break; } default: { DoNothing(); DoSomething(); break; } }

值:2

switch (a) { case 1: { DoThis(); DoThat(); break; } case 2: { DoIt(); DoItAgainWithLove(); break; } default: { DoNothing(); DoSomething(); break; } }

switch 语句中多行 'case' 部分周围

属性名称:

[resharper_]csharp_blank_lines_around_multiline_case_section[resharper_]blank_lines_around_multiline_case_section

可能的值:

整数

示例:

值:0

switch (a) { case 1: DoThis(); break; case 2: DoThat(); break; default: DoNothing(); break; }

值:1

switch (a) { case 1: DoThis(); break; case 2: DoThat(); break; default: DoNothing(); break; }

值:2

switch (a) { case 1: DoThis(); break; case 2: DoThat(); break; default: DoNothing(); break; }

switch 语句中的 'case' 前

属性名称:

[resharper_]csharp_blank_lines_before_case[resharper_]blank_lines_before_case

可能的值:

整数

示例:

值:0

switch (a) { case 1: return x; case 2: return y; default: return 0; }

值:1

switch (a) { case 1: return x; case 2: return y; default: return 0; }

值:2

switch (a) { case 1: return x; case 2: return y; default: return 0; }

switch 语句中的 'case' 后

属性名称:

[resharper_]csharp_blank_lines_after_case[resharper_]blank_lines_after_case

可能的值:

整数

示例:

值:0

switch (a) { case 1: DoThis(); DoThat(); break; case 2: DoIt(); DoItAgainWithLove(); break; default: DoNothing(); DoSomething(); break; }

值:1

switch (a) { case 1: DoThis(); DoThat(); break; case 2: DoIt(); DoItAgainWithLove(); break; default: DoNothing(); DoSomething(); break; }

值:2

switch (a) { case 1: DoThis(); DoThat(); break; case 2: DoIt(); DoItAgainWithLove(); break; default: DoNothing(); DoSomething(); break; }
最后修改日期: 2025年 9月 26日