简体   繁体   English

如何从 Visual Studio 2022 中的命名空间中删除花括号

[英]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 semicolon namespace_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.

相关问题 在Visual Studio 2012中使用Curly括号自动完成 - Curly braces autocomplete in Visual Studio 2012 如何使用 C# 从 xml 中删除花括号 - How to remove curly braces from the xml using C# 从其他地方复制代码后如何停止Visual Studio 2022自动添加命名空间 - How to stop Visual Studio 2022 to add namespace automatically after copy codes from other place 如何从 Visual Studio 2022 运行 WcfTestClient? - How to run WcfTestClient from Visual Studio 2022? 用户控件命名空间错误visual studio 2022 - Usercontrol namespace error visual studio 2022 Visual Studio 2015如何在if语句之后快速将现有代码移动到新放置的花括号中? - Visual Studio 2015 How to quickly move existing code after if statement into newly placed curly braces? 在花括号内按 Enter 时如何使 vscode 的行为类似于 Visual Studio IDE - How to make vscode act like Visual Studio IDE when pressing Enter within curly braces 从 NuGet package Visual Studio 2022 中删除或更新库依赖项 - Remove or Update library dependency from NuGet package Visual Studio 2022 如何在 Visual Studio 2022 的 WinForms 中删除方形鼠标指针 - How to remove the Square mouse pointer in WinForms in Visual Studio 2022 Visual Studio可以从声明中删除显式命名空间吗? - Can Visual Studio remove explicit namespace from declarations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM