dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
505 stars 195 forks source link

Enhancement: Blazor / Razor infer @ref definitions from razor language. #7651

Open njannink opened 4 years ago

njannink commented 4 years ago

When defining a reference @ref to a html element or razor component you now need to define it double:

<Component @ref="myComponent">Hello Blazor!</Component>

@code {
    private Component myComponent;

    void DoSomething() => myComponent.ShowMessage();
}

You now need to define the type and name twice, both in the razor language and in de code block. Making refactoring / code maintenance more difficult when eg the Component is renamed. It would be a great improvement if the reference in the code block doesnt need to defined aswell. But that it's inferred from the razor language.

Same as for example in Wpf. There your can give a Name to a element and then it's available in the code-behind

So the final solution will be then be:

<Component @ref="myComponent">Hello Blazor!</Component>

@code {
    void DoSomething() => myComponent.ShowMessage();
}
njannink commented 4 years ago

Also one other thing is that now Visual Studio complains about the fields in the code behind:

CS0649  Field 'xxxx' is never assigned to, and will always have its default value null
mkArtakMSFT commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.