-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Blazor] Support for primitive types in [SupplyParameterFromForm] #48432
Conversation
b9eddae
to
f025ae0
Compare
f9504c8
to
0ac09b7
Compare
cfbeda2
to
66c3f89
Compare
470b2be
to
23b534b
Compare
50b3aa3
to
3ff60a4
Compare
0745e8c
to
11c7bd8
Compare
20a9175
to
ee67e2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple questions but this looks great to me.
return result; | ||
} | ||
|
||
// We don't do error handling yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an issue tracking the remaining error handling work? I couldn't find one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's covered as part of #46688
|
||
internal abstract class FormDataConverter<T> : FormDataConverter | ||
{ | ||
internal abstract bool TryRead(ref FormDataReader context, Type type, FormDataMapperOptions options, out T? result, out bool found); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is type
ever going to be different from typeof(T)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not obvious yet in this PR, but it's passed in for a different reason. When you do typeof(T)
the generated code needs to ask the type system at runtime (this is in IL) for the type instance, which involves a lookup. For that reason, many serializers cache and pass the type instance along.
If you look at System.Text.Json, they do something similar. See here
The other part is that we might still need this if in the future we want to support polymorphic binding or enable people to do so, so we can't just assume typeof(T) == type in general.
FormDataMapper is the entry point for mapping form values into a type, it receives a FormDataReader and FormDataMapperOptions. The options contain an internal collection of converters and factories that are used to define how to bind a given type.
For well-known types we prepopulate the list of converters.
#46688 (comment)
Some basic benchmark data against MVC. Beware that this is with any of the main optimizations.