Hacker News new | ask | show | jobs
by HideousKojima 1689 days ago
Doesn't really bother me, so long as the global usings are only kept to a single file. Intellisense will tell you the full namespace, then you can just see if you've got that namespace in the file you're in or in your dedicated global usings file.
2 comments

> so long as the global usings are only kept to a single file

Here's where the mess starts.

It seems far too easy to sneak a global import statement in to random files and then have the entire codebase polluted by it.

I feel like this is too foot-gun'y, myself.

Yeah, there should definitely be a way to have the compiler enforce global usings in only a specific file.
I thought it was generally considered good practice to put extension methods into static classes in their own file. So like `FooExtensions.cs` if you are writing extensions for the `Foo` class.

I would consider this the same: Project should have a `GlobalUsings.cs` file.

Does C# have any linters available that could enforce such a conventions?

C# has a framework in-place to facilitate workspace-specific linters, so even if one doesn't exist, it could be written very easily (and premade ones are sure to appear quickly).

https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tu...