本文中的格式设置选项适用于 C# 和 Visual Basic。 这些是代码样式规则 IDE0055 的选项。
using 指令选项
使用这些选项可自定义要 using 如何对指令进行排序和分组:
.editorconfig 文件示例:
# .NET formatting rules
[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true
提示
还提供了单独的 C# 特定 using 指令规则 IDE0065。 该规则涉及 using 指令是放置在命名空间之内还是之外。
dotnet_sort_system_directives_first
| 属性 | 价值 | 说明 |
|---|---|---|
| 选项名称 | dotnet_sort_system_directives_first | |
| 适用的语言 | C# 和 Visual Basic | |
| 引入的版本 | Visual Studio 2017 | |
| 选项值 | true |
按字母顺序对指令进行排序System.*using,并将其放置在其他using指令之前。 |
false |
不要在其他System.*指令之前放置usingusing指令。 |
|
| 默认选项值 | true |
代码示例:
// dotnet_sort_system_directives_first = true
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit;
// dotnet_sort_system_directives_first = false
using System.Collections.Generic;
using Octokit;
using System.Threading.Tasks;
dotnet_separate_import_directive_groups
| 属性 | 价值 | 说明 |
|---|---|---|
| 选项名称 | dotnet_separate_import_directive_groups | |
| 适用的语言 | C# 和 Visual Basic | |
| 引入的版本 | Visual Studio 2017 | |
| 选项值 | true |
在 using 指令组之间放置一个空白行。 |
false |
不在 using 指令组之间放置空白行。 |
|
| 默认选项值 | false |
代码示例:
// dotnet_separate_import_directive_groups = true
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit;
// dotnet_separate_import_directive_groups = false
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit;