Allow single parameter with any type when binding to method - #21867
Merged
Conversation
|
You can test this PR using the following package version. |
maxkatz6
reviewed
Jul 28, 2026
maxkatz6
reviewed
Jul 28, 2026
maxkatz6
previously approved these changes
Jul 28, 2026
MrJul
force-pushed
the
fix/binding-method-resolution
branch
from
July 28, 2026 12:38
a6e774e to
3fd9a40
Compare
maxkatz6
approved these changes
Jul 28, 2026
|
You can test this PR using the following package version. |
MrJul
added a commit
that referenced
this pull request
Jul 29, 2026
* Allow single parameter with any type when binding to method * Port method binding logic to ReflectionBinding * Don't depend on the order of methods * Handle overrides properly * Fix nullability warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
#21617 made the chosen overload consistent when binding a command property to a method, instead of it being undefined behavior: the parameter must be an
object.While doing so, it also broke code that strongly typed the parameter with a single overload, see #21833.
This PR improves the logic to allow a single overload with a single parameter to always match (the parameter's type doesn't matter in this case), which should cover the most common scenarios, as view models don't typically overload such methods.
New logic
object, it is chosen.Any other combination results in an error. For example multiple one-parameter overloads (without
object) don't work. There is no overload resolution matching C#: we don't want to implement such a complex algorithm, and the exact parameter type might not be known at compile time.These changes apply to both compiled and reflection bindings.
There is still one difference between the two binding types though: reflection bindings convert the parameter to the proper type at runtime, compiled bindings don't (the correct type must be passed, or an
InvalidCastExceptionis thrown). This is to avoid callingTryConvert, which isn't AOT-compatible. I'm not a fan of this difference and will be happy to further discuss it.Fixed issues