c# - 将代码与空格对齐时阻止 IDE0055 样式分析器

标签 c# .net roslyn-code-analysis

我使用一种非常常见的格式化技术,通过对齐代码来提高可读性。

例如1 带有声明(可能通过 csharp_space_around_declaration_statements )

var a    = foo;
var bc   = 123;
var some = thing;

例如2 不带声明

a    = foo;
bc   = 123;
some = thing;

但我使用的是 roslyn 分析器,这会触发 IDE0055:Fix formatting(对于前两行)。

.editorconfig 中,是否有允许此样式的 dotnet_xxxcsharp_xxx 配置选项(或组合)?

最佳答案

.editorconfig 中设置 csharp_space_around_declaration_statements = ignore

此设置位于 Text editor -> C# -> Code Style -> Formatting -> Spacing -> ignore spaces in declaration statements

虽然我不知道在模式匹配中禁用自动套用格式的方法:

static int Foo(int x, int y) => (x, y) switch
{
    (    0,     0) => 0,
    (int i,     0) => 11,
    (int i, int j) => i + j,
};

关于c# - 将代码与空格对齐时阻止 IDE0055 样式分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66315458/

相关文章:

c# - 如何在 C# Visual Studio 中删除 CheckBox 的焦点边框?

c# - 如何在数据表中查找匹配的记录

nuget - 使用新的csproj格式将文件放在nutkg中的 "analyzer"目录中

.net - 如果存在 Microsoft SQL Server 实例,则绕过 SQLExpress 的安装

c# - 使用 msbuildworkspace 打开解决方案会给出没有详细信息的诊断错误

c# - FxCop 分析器不会即时显示警告

C# ToList 性能和替代方法

c# - 热带矩阵乘法

java - IKVM 复杂自定义类型在重新映射到属性时出错!

c# - 如何使用 C# 跨域验证域用户凭据?