Skip to content
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

Clean up namespaces generated by extract to code-behind gesture #8766

Closed
danroth27 opened this issue May 25, 2023 · 1 comment · Fixed by #9263
Closed

Clean up namespaces generated by extract to code-behind gesture #8766

danroth27 opened this issue May 25, 2023 · 1 comment · Fixed by #9263
Assignees
Milestone

Comments

@danroth27
Copy link
Member

You get a lot of namespaces when you use the extract to code-behind gesture:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using BlazorApp53;
using BlazorApp53.Shared;

namespace BlazorApp53.Pages
{
    public partial class Counter
    {
        private int currentCount = 0;
        private void IncrementCount()
        {
            currentCount++;
        }
    }
}

Can we clean these up to only the required ones?

@ghost ghost added the untriaged label May 25, 2023
@davidwengier
Copy link
Contributor

When I do this, I also get global:: aliases on most of the using declarations. We should remove them too, they're an implementation detail of the generated C# from the Razor compiler.

@davidwengier davidwengier added this to the 17.8 Planning milestone Jul 20, 2023
@ghost ghost removed the untriaged label Jul 20, 2023
@davidwengier davidwengier self-assigned this Sep 11, 2023
davidwengier added a commit that referenced this issue Sep 14, 2023
Fixes #4330
Fixes #8766
Includes #9262 so just review from
8a2b8af
onwards

Goes with dotnet/roslyn#69878 and
dotnet/vscode-csharp#6329

I logged #9264 to follow up with a
better test, though strictly speaking the one I've added id exhaustive
:)

Behaviour of Extract to Code Behind before this change. Note the many
using statements and block scoped namespace.

![ExtractToCodeBehindBefore](https://github.com/dotnet/razor/assets/754264/10ac5595-b3b2-44c2-a1a7-66664d3c8f1b)

Behaviour after this change. Note the file scoped namespace, and file
header.

![ExtractToCodeBehindAfter](https://github.com/dotnet/razor/assets/754264/65160715-bc98-4336-b19d-37f9b14adf94)

The squiggle on `NavigationManager` is due to an `.editorconfig` rule I
have on in that project, requiring `this.` qualification, so is
unrelated.
@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants