Skip to content

Migrate all source files to file-scoped namespaces - #17470

Open
ViktorHofer wants to merge 1 commit into
dotnet:mainfrom
ViktorHofer:viktorhofer/file-scoped-namespaces
Open

Migrate all source files to file-scoped namespaces#17470
ViktorHofer wants to merge 1 commit into
dotnet:mainfrom
ViktorHofer:viktorhofer/file-scoped-namespaces

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Converts all C# sources to file-scoped namespaces and enforces the style going forward.

  • Converted 1013 .cs files with a Roslyn-based transform; each file was validated by comparing the before/after token streams, and lines inside multi-line string literals were left un-dedented.
  • .editorconfig: added csharp_style_namespace_declarations = file_scoped and dotnet_diagnostic.IDE0161.severity = error to the [*.cs] section.
  • Updated the SwaggerGenerator .hb templates so regenerated Helix client code stays file-scoped.
  • Updated ToolsetInfo.cs.pp, which is generated into obj and analyzed.
  • Split the #if !NET DynamicallyAccessedMembersAttribute polyfill out of StaticReflectionConstants.cs so the remaining namespace can be file-scoped.
  • HelixJobInfo.cs: the trailing file class now lives inside the namespace; removed the redundant self-using.

Note: the C# style rules from # New line preferences down to IDE0073 currently sit under the [*.{wixproj,wxs,wxi,wxl,thm}] section and are therefore inert. That pre-existing issue is not addressed here, which is why the new rule was placed in [*.cs].

Validated with build.cmd -configuration Release -test: 0 warnings, 0 compile errors.

Enforce via IDE0161 as an error in .editorconfig.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d271fdd-ba34-4ec9-ae26-a77283e22196
Copilot AI lite review requested due to automatic review settings September 1, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Review tier: Lite
Findings: 3 Low severity

New issues introduced by this change (3)
Severity Finding
Low severity src/​Microsoft.DotNet.Build.Manifest/​AssetManifestModel.cs — The doc comment has a duplicated word ("not not"), which reads as a typo and makes the API docs…
Low severity src/​Microsoft.DotNet.XUnitConsoleRunner/​src/​common/​AssemblyResolution/​_DiagnosticMessage.cs — The constructor doc comment references DiagnosticMessage, but this type is _DiagnosticMessage.…
Low severity src/​Microsoft.DotNet.XUnitExtensions.Shared/​Attributes/​LinuxOnlyTheoryAttribute.cs — The XML doc summary says this attribute should be run only on Windows, but the type is…
What changed in this PR

This pull request migrates the Arcade repo’s C# codebase to file-scoped namespaces and adds enforcement so future changes stay consistent. It also updates code-generation inputs so regenerated sources keep the same namespace style.

Changes:

  • Converted the C# sources to file-scoped namespaces (namespace X;) across the repo.
  • Enforced the style via .editorconfig (csharp_style_namespace_declarations = file_scoped + IDE0161 as error).
  • Updated shared/codegen inputs (e.g., Helix/Swagger generator templates and shared items) to preserve file-scoped namespaces in generated output.
File Description
.editorconfig Enforces file-scoped namespaces (IDE0161 as error) going forward.
src/​Microsoft.DotNet.XUnitExtensions.Shared/​Microsoft.DotNet.XUnitExtensions.Shared.projitems Adds the DynamicallyAccessedMembersAttribute polyfill to the shared compile items.
src/​Microsoft.DotNet.XUnitExtensions.Shared/​Attributes/​LinuxOnlyTheoryAttribute.cs File-scoped namespace conversion; contains a doc-comment inconsistency flagged in review.
src/​Microsoft.DotNet.Build.Manifest/​AssetManifestModel.cs File-scoped namespace conversion; contains a doc-comment typo flagged in review.
src/​Microsoft.DotNet.XUnitConsoleRunner/​src/​common/​AssemblyResolution/​_DiagnosticMessage.cs File-scoped namespace conversion; contains a doc-comment reference issue flagged in review.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +11 to +13
/// <summary>
/// The asset manifest is not not represented as XML
/// </summary>
Comment on lines +10 to +13
/// <summary>
/// Initializes a new instance of the <see cref="DiagnosticMessage"/> class.
/// </summary>
/// <param name="message">The message to send</param>
Comment on lines +11 to +13
/// <summary>
/// This test should be run only on Windows.
/// </summary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants