-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[code style] Prefer file-scope namespaces #28040
[code style] Prefer file-scope namespaces #28040
Conversation
Hey there @MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
@@ -67,6 +67,10 @@ csharp_style_var_for_built_in_types = true:none | |||
csharp_style_var_when_type_is_apparent = true:none | |||
csharp_style_var_elsewhere = false:none | |||
|
|||
# Namespace preference (prefer file-scoped namespaces) | |||
csharp_style_namespace_declarations = file_scoped | |||
dotnet_diagnostic.IDE0161.severity = suggestion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion to avoid waaaay too many warnings.
@@ -67,6 +67,10 @@ csharp_style_var_for_built_in_types = true:none | |||
csharp_style_var_when_type_is_apparent = true:none | |||
csharp_style_var_elsewhere = false:none | |||
|
|||
# Namespace preference (prefer file-scoped namespaces) | |||
csharp_style_namespace_declarations = file_scoped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picked up by MSVS when user creates a new type (class, interface, etc.).
/azp run |
1 similar comment
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Description of Change
This PR adds a suggestion to use file-scoped namespaces (if possible) using IDE0161 analyzer.
The documentation page mentions:
This PR was created because when file-scoped namespaces are used, then there is bigger chance that two files can be worked on one display which leads to improved productivity.
What are file-scoped namespaces?
C# originally allowed only block-scoped namespaces:
Modern C# versions support:
as it saves one level of indentation, so more code fits on your screen.