Visual Studio 2017 shows a hint for unnecessary this
qualifiers even when the inspection is disabled in the options.
This is how it looks:
(First line is the culprit, second line is how I want this
to always look like.)
Hovering over the grayed out this
and clicking on the light bulb shows this suggested fix:
I can't find a way of disabling this completely. Sometimes I want to have "unnecessary" this
qualifiers and sometimes I don't, so I don't want VS to comment about this at all.
"None" is the least severe option yet it still shows this annoying, different color.
Is there any possibility of complete disabling this inspection?
You can use a ruleset file to disable any analysis if you know its diagnostic id (in this case 'IDE0003')
On the References
node of you project right click on Analyzers
and select Open Active Rule Set
Once the ruleset editor is open just search for IDE0003
and uncheck the checkbox. Then save the ruleset file. Then save the project.
<CodeAnalysisRuleSet>ConsoleApp9.ruleset</CodeAnalysisRuleSet>
Looks like the current process is more complicated for .NET Core and .NET Standard projects.
From MS VS Docs:
If you have a .NET Core or .NET Standard project, the process is a little different because there's no Code Analysis property tab. Follow the steps to copy a predefined rule set to your project and set it as the active rule set. After you've copied over a rule set, you can edit it in the Visual Studio rule set editor by opening it from Solution Explorer. [emphasis mine]
Taking the first link in that quote will eventually take you, after a little sleuthing, to Code style rule options, that finally tells you how to add the file:
In Visual Studio, you can generate this file and save it to a project at Tools > Options > Text Editor > [C# or Basic] > Code Style > General. Then, click the Generate .editorconfig file from settings button.
NOTE: This produces a tiny warning just under your toolbars that an
.editorconfig
has been added to your solution. Select the "Yes" button to include it in your solution.
And now you can open and edit your new .editorconfig
file.
Looks like this is the "offending" section:
# this. and Me. preferences
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_property = false:suggestion
If that dotnet_style_qualification_for_property
is changed to = true:suggestion
(explanation here), I think you're golden [at least for properties, of course -- make edits as appropriate].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With