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

Simpler way to declare two-way bound parameters in Blazor components #28690

Closed
lindespang opened this issue Dec 16, 2020 · 1 comment
Closed
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@lindespang
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I find myself writing a lot of boilerplate code when doing two-way bindings in Blazor like below. (It adds up if you have multiple parameters..)

@code {
    [Parameter]
    public TValue Value { get; set; }

    [Parameter]
    public EventCallback<TValue> ValueChanged { get; set; }
}

I think it would be nice to introduce another attribute that would generate the same source by only declaring one property.

Describe the solution you'd like

I would like it to look something like below (attribute semantics up for discussion)

@code {
    [BindableParameter]
    public TValue Value { get; set; }
}

Which would generate exactly the same source as

@code {
    [Parameter]
    public TValue Value { get; set; }

    [Parameter]
    public EventCallback<TValue> ValueChanged { get; set; }
}

Additional context

If I haven't missed anything obvious here I think this is a very clean and non-intrusive solution. I always write my bindable properties like this and have not yet encountered any situation that breaks that rule. Therefor I think this added attribute makes sense.

Please give feedback on this and let me know if I should take a look at it or if you want to do it yourselves!

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Dec 16, 2020
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
We plan to implement source generators for Razor in .NET 6. Once that work is done, you'll be able to implement your own source generator which would do what you want.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants