Skip to content

Add support for TypeConverter #10730

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

Merged
merged 4 commits into from
Jun 5, 2019
Merged

Add support for TypeConverter #10730

merged 4 commits into from
Jun 5, 2019

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Jun 1, 2019

Fixes: #9632
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.

Note: this change is targeting preview 7.

@rynowak
Copy link
Member Author

rynowak commented Jun 1, 2019

In EventCallbackFactoryBinderExtensions class it is parsing numbers using the CurrentCulture, and that can give different results depending on the machine where the app is ran. Shouldn't it use InvariantCulture?

Sadly, it's not that simple. See: #9386 which tracks all of the work in this area. InvariantCulture will result in the correct behavior for an <input type="number"> but not for other field types like <input type="text">

This PR doesn't cover fixing that issue, and as far as I know just makes the current behavior more clearly explicit. We definitely plan to address this before release.

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jun 3, 2019
Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my questions about InvariantCulture vs CurrentCulture, this looks great!

Approving now in case it's possible to resolve those last details and merge in time for preview 6.

@rynowak
Copy link
Member Author

rynowak commented Jun 3, 2019

Sadly we're out of time, this isn't going to make it for preview 6.

@rynowak rynowak added this to the 3.0.0-preview7 milestone Jun 3, 2019
@rynowak rynowak force-pushed the rynowak/converters branch from db88626 to c47c4fb Compare June 3, 2019 21:28
Ryan Nowak and others added 4 commits June 3, 2019 15:49
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`.
kzu added a commit to kzu/aspnetcore that referenced this pull request Apr 15, 2023
It's quite convenient to be able to bind directly to data containing raw HTML. This is quite convoluted to do today, requiring registering a TypeDescriptionProvider, which in turn returns a custom type descriptor which in turn can provide the missing TypeConverter for the desired type.

This adds support out of the box for binding straight to markup strings.

Follows the implementation and tests from dotnet#10730.

Closes dotnet#47718
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
4 participants