禁用主构造函数的推荐/IDE0290

问题描述 投票:0回答:1

我对主构造函数不太满意 - 因为构造函数参数不是只读的,在我看来它太容易出错,特别是在使用接收自己的构造函数参数副本的基类时。

但是 Visual Studio 和 Resharper 都建议我使用主构造函数。我觉得这很烦人。如何禁用此类建议?或者更好的是,添加一个检查报告找到的主要构造函数,这样我就不会意外创建它们?

视觉工作室:

再磨刀:

c# visual-studio constructor resharper primary-constructor
1个回答
0
投票

添加

.editorconfig
文件,并将
csharp_style_prefer_primary_constructors
设置为 false:

[*.cs]

csharp_style_prefer_primary_constructors = true

或者通过代码禁用规则:

[*.cs]

dotnet_diagnostic.IDE0290.severity = none
© www.soinside.com 2019 - 2024. All rights reserved.