Disable recommendation for primary constructors / IDE0290

760 Views Asked by At

I am not so happy with primary constructors - because the constructor parameters are not readonly, it's too error prone in my opinion, especially when working with base classes which receive their own copy of the constructor parameters.

However Visual Studio and Resharper both recommend me to use primary constructors. I find that quite annoying. How can I disable such recommendations? Or even better, add a check reporting found primary constructors so I can't accidently create them?

Visual Studio: enter image description here

Resharper: enter image description here

2

There are 2 best solutions below

0
On

Try adding .editorconfig file with csharp_style_prefer_primary_constructors set to false:

[*.cs]

csharp_style_prefer_primary_constructors = false

Or alternatively disable the rule by the code:

[*.cs]

dotnet_diagnostic.IDE0290.severity = none

See also the Use primary constructor (IDE0290) rule doc.

0
On

in YourSolution.sln.DotSettings file you can add:

<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToPrimaryConstructor/@EntryIndexedValue">DO_NOT_SHOW</s:String>

In R# you can configure it via GUI by context menu: "Inspection 'Convert constructor into primary constructor'" / "Configure inspection severity" - in popup "Inspection Options" select "Do not show" and Save To - Solution "..." team-shared