tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Removing explicit default access modifiers in Visual Studio using EditorConfig

2 Jun 2020 1 mins .NET, C#, Visual Studio

Almost five years ago I wrote post Removing explicit default access modifiers (Roslyn analyzer and codefix) and it was a great exercise and I still prefer to have code without all the private, etc. noise. But also nowadays Visual Studio supports all sorts of code style rules via EditorConfig file. Can I teach Visual Studio to actually suggest removing explicit default access modifiers?

I was expecting it to require bit of persuasion, but instead it was smooth sailing. The key for EditorConfig is called dotnet_style_require_accessibility_modifiers and simply setting it to omit_if_default (probably omit_if_default:suggestion) does all the magic.

Although it works fine, it’s clear that using this setting is not exactly expected in terms of what Visual Studio tells you you should do. 😃

First, in hint, it tells you “Accessibility modifiers required”.

Accessibility modifiers required

And then, when you invoke the code fix, it calls the action “Add accessibility modifiers”. Which is actually exactly the opposite of what is going to happen.

Add accessibility modifiers

But I take it. Similar to the preference between spaces and tabs, not using the explicit default access modifiers is niche choice in .NET world, as far as I can tell. And this is easier than introducing the analyzer into the project(s) (and potentially maintaining it).

Probably Miguel de Icaza and I should start a gang.

Profile Picture Jiří Činčura is an independent developer, .NET, C# and Firebird expert, focusing on data and business layers, language constructs, parallelism, databases and performance. He's Microsoft Most Valuable Professional and frequent speaker. You can read his articles, guides and tips and tricks at