[英]how to remove curly braces from a namespace in visual studio 2022
I would like to know how I can remove the braces from a namespace and have it be closed with a semicolon (;).我想知道如何从命名空间中删除大括号并用分号 (;) 将其关闭。
actually:实际上:
namespace ProductsGroup{
public void save{
}
}
I need:我需要:
namespace ProductsGroup;
public void save{
}
Thanks you!谢谢!
Unless you are compiling against C# 10 with file-scoped namespaces , you can't do this.除非您使用文件范围的命名空间针对 C# 10 进行编译,否则您不能这样做。 (Bold added)
(加粗)
A namespace_declaration consists of the keyword
namespace
, followed by a namespace name and body , optionally followed by a semicolonnamespace_declaration包含关键字
namespace
,后跟命名空间名称和正文,可选地后跟分号
A body requires curly braces.身体需要花括号。
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/namespaces https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/namespaces
Visual-Studio 2022 already offers this refactoring (and the reverse). Visual-Studio 2022 已经提供了这种重构(反之亦然)。
Additionally you can set a preference in Visual Studio's C# Code Style settings, and in .editorconfig
.此外,您可以在 Visual Studio 的 C# 代码样式设置和
.editorconfig
中设置首选项。
More details: https://www.ilkayilknur.com/how-to-convert-block-scoped-namespacees-to-file-scoped-namespaces更多详细信息: https://www.ilkayilknur.com/how-to-convert-block-scoped-namespacees-to-file-scoped-namespaces
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.