Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable recommendation for primary constructors / IDE0290

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

like image 792
stefan.at.wpf Avatar asked Sep 05 '25 03:09

stefan.at.wpf


1 Answers

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.

like image 148
Guru Stron Avatar answered Sep 07 '25 16:09

Guru Stron