Skip to content

typeparam bind error #9632

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

Closed
ghost opened this issue Apr 22, 2019 · 4 comments · Fixed by #10730
Closed

typeparam bind error #9632

ghost opened this issue Apr 22, 2019 · 4 comments · Fixed by #10730
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one

Comments

@ghost
Copy link

ghost commented Apr 22, 2019

Hi, in Blazor 0.10 such code stopped working

@typeparam TItem

<input bind="@line" />

@functions{
    [Parameter]
    TItem line { get; set; }
}

This is a build error of version 0.10 or is the ability to typeparam bind removed ?, is there an alternative solution to the problem?

@blowdart blowdart added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 22, 2019
@danroth27 danroth27 added area-blazor Includes: Blazor, Razor Components investigate labels Apr 22, 2019
@danroth27 danroth27 added this to the 3.0.0-preview5 milestone Apr 22, 2019
@ghost
Copy link
Author

ghost commented Apr 22, 2019

Type of error at build time
CS0029 C# Cannot implicitly convert type 'string' to

dotnet --version
3.0.100-preview4-011223
Microsoft Visual Studio Enterprise 2019 Preview 
16.1.0 Preview 1.0

@rynowak
Copy link
Member

rynowak commented Apr 22, 2019

This is definitely an issue, but I'm not sure that I'm totally convinced this ever worked unless TItem is limited to enums.

We used to have a generic overload of the binding functionality that didn't use the enum type constraint. It would throw for non-enum types. https://github.com/aspnet/AspNetCore/blob/v3.0.0-preview4-19216-03/src/Components/Components/src/BindMethods.cs#L273

The new methods have a similar method but with the enum constraint. https://github.com/aspnet/AspNetCore/blob/master/src/Components/Components/src/EventCallbackFactoryBinderExtensions.cs#L595

I think we need to address this in general though since we have enums in our programming model. This means we'll need to add a general-purpose bind/converter.

@rynowak rynowak removed this from the 3.0.0-preview5 milestone Apr 22, 2019
@rynowak rynowak added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed investigate labels Apr 22, 2019
@rynowak rynowak removed their assignment Apr 22, 2019
@danroth27 danroth27 added this to the 3.0.0-preview7 milestone Apr 23, 2019
@rynowak
Copy link
Member

rynowak commented Apr 29, 2019

Example of the generated code:

#pragma checksum "C:\Users\rynowak\source\repos\Blazor1\Blazor1.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "49595bbe8c7c44c17ab89283a7e51479d3e64ea6"
// <auto-generated/>
#pragma warning disable 1591
namespace Blazor1
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
    using System.Net.Http;
    using Microsoft.AspNetCore.Components.Forms;
    using Microsoft.AspNetCore.Components.Layouts;
    using Microsoft.AspNetCore.Components.Routing;
    using Microsoft.JSInterop;
    using Blazor1.Shared;
    public class Blazor1<T> : Microsoft.AspNetCore.Components.ComponentBase
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder)
        {
            builder.AddMarkupContent(0, "<h3>Blazor1</h3>\r\n\r\n");
            builder.OpenElement(1, "input");
            builder.AddAttribute(2, "type", "text");
            builder.AddAttribute(3, "value", Microsoft.AspNetCore.Components.BindMethods.GetValue(value));

            // There is no generic version of CreateBinder 
            builder.AddAttribute(4, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => value = __value, value));
            builder.CloseElement();
        }
        #pragma warning restore 1998
#line 7 "C:\Users\rynowak\source\repos\Blazor1\Blazor1.razor"
            
    T value;

#line default
#line hidden
    }
}
#pragma warning restore 1591

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: 3.0.0-preview7, 3.1.0 May 24, 2019
rynowak pushed a commit that referenced this issue Jun 1, 2019
Fixes: #8493
Fixes: #9632
Fixes: #9339
Fixes: #8385
Fixes: 10077

This fix adds support for type converters as well as a few other minor
things we were missing from binding. The key thing about supporting
conversions is that we new can support arbitrary types with `@bind`.
This means you can use it with generics, which is something many users
have tried.

Along with type converters we get Guid and TimeSpan from the BCL. The
BCL also includes converters for types we're less interested in like
`short`.
rynowak pushed a commit that referenced this issue Jun 3, 2019
Fixes: #8493
Fixes: #9632
Fixes: #9339
Fixes: #8385
Fixes: 10077

This fix adds support for type converters as well as a few other minor
things we were missing from binding. The key thing about supporting
conversions is that we new can support arbitrary types with `@bind`.
This means you can use it with generics, which is something many users
have tried.

Along with type converters we get Guid and TimeSpan from the BCL. The
BCL also includes converters for types we're less interested in like
`short`.
rynowak added a commit that referenced this issue Jun 5, 2019
* Add support for TypeConverter

Fixes: #8493
Fixes: #9632
Fixes: #9339
Fixes: #8385
Fixes: 10077

This fix adds support for type converters as well as a few other minor
things we were missing from binding. The key thing about supporting
conversions is that we new can support arbitrary types with `@bind`.
This means you can use it with generics, which is something many users
have tried.

Along with type converters we get Guid and TimeSpan from the BCL. The
BCL also includes converters for types we're less interested in like
`short`.

* Use correct NumberStyles

* Fix culture

* Core check
@rynowak
Copy link
Member

rynowak commented Jun 5, 2019

This has been added in preview 7 - #10730
Note that preview 6 is the next release so you will have to wait a few weeks.

@rynowak rynowak self-assigned this Jun 5, 2019
@rynowak rynowak modified the milestones: 3.1.0, 3.0.0-preview7 Jun 5, 2019
@mkArtakMSFT mkArtakMSFT added the Done This issue has been fixed label Jun 7, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants