codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.88k stars 353 forks source link

Use file scoped namespaces #978

Open RihanArfan opened 1 year ago

RihanArfan commented 1 year ago

It would be nice if CodeMaid supported formatting to file scoped namespaces.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces

This is supported in C# 10, and .NET 6+.

codecadwallader commented 1 year ago

Thanks for the suggestion! A first step here would be to review the FileCodeModel and see how it affects members, and if it is registered the same way or differently than the regular namespace approach.

sgf commented 1 week ago

This should be easy to implement. Check whether there is only one namespace in the file. If so, then automatically Use file scoped namespaces, otherwise give up.

In VS2022, when the file is opened, if you add a semicolon to the end of the namespace line, VS will automatically handle it (delete its brace pair);

动画13