Skip to content

Why not save one more line with file-scoped namespaces? #44676

@guardrex

Description

@guardrex

Summary

Couldn't the framework (and doc examples) save one more vertical line with file-scoped namespaces by collapsing the namespace line into any lines at the top of the file (e.g., make it the last line or the first line)?

Motivation and goals

My understanding is that one of the benefits of this feature is to vertically collapse code. As implemented today, it only saves one line that doesn't affect scrolling. Only the final brace } line is dropped/saved.

Risks / unknowns

I think the risk of disorganization is low.

Example

src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Pages/Error.cshtml.cs:

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ComponentsWebAssembly_CSharp.Server.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
    ...
}

... TO ...

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ComponentsWebAssembly_CSharp.Server.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
    ...
}

... OR with the namespace at the top of the file ...

namespace ComponentsWebAssembly_CSharp.Server.Pages;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
    ...
}

🤔

I kind'a like it at the top of the file. That locates it quickly at a glance 👀, which is all that placing it on a line with vertical space around it seems to accomplish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    design-proposalThis issue represents a design proposal for a different issue, linked in the description

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions