codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Use file scoped namespaces

Open RihanArfan opened this issue 2 years ago • 3 comments

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+.

RihanArfan avatar Feb 20 '23 10:02 RihanArfan

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.

codecadwallader avatar Mar 26 '23 19:03 codecadwallader

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

sgf avatar Jul 18 '24 02:07 sgf