-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support Nullable Bindable Properties in TypedBinding.cs
#371
base: main
Are you sure you want to change the base?
Conversation
Remove the null value Exception
@@ -248,7 +248,7 @@ void ApplyCore(TSource? sourceObject, BindableObject target, BindableProperty pr | |||
var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource; | |||
if (needsSetter && sourceObject is not null) | |||
{ | |||
var value = GetTargetValue(target.GetValue(property), typeof(TProperty)) ?? throw new InvalidOperationException("Unable to find target value"); | |||
var value = GetTargetValue(target.GetValue(property), typeof(TProperty)); |
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.
I wonder if we should check whether TProperty
is nullable in this scenario. Thoughts @TheCodeTraveler?
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.
Thanks @JoeVoo! Could you please add unit tests that demonstrate the bug you are fixing and that verify the fix in this PR? It'd be great if you could also update the sample app to include a demonstration of how users were impacted; we use the sample app as a regression test against new PRs to ensure they don't break any existing behavior.
I've re-added the PR Checklist
from our Pull Request Template to this PR Description that contains this checklist.
@dotnet-policy-service agree |
Nullable reference types are enabled in the Unit Tests. I think this happens only in a 'nullable ref type disabled' project. But i am no test specialist. I try to avoid using enable. public partial class EnumPicker<T> : Picker where T : struct, Enum
...
public static readonly BindableProperty SelectedValueProperty =
BindableProperty.Create(
nameof(SelectedValue),
typeof(T?),
typeof(EnumPicker<T>),
null,
BindingMode.TwoWay,
null,
propertyChanged: SelectedValue_Changed); typeof(T?) and EnumOfT is not nice, but the only way i found to set it null |
@bijington , what is your scenario to get the exception? |
I am not experiencing this issue but I would be happy to try and contribute a unit test which would highlight the issue and fix if that helps? |
TypedBinding.cs
newerly i got an error message on the TryConvert line with ref value is null. I managed this with the added lines.
Remove the null value Exception
Description of Change
Remove the exception fired on null value that is not needed
var value = GetTargetValue(target.GetValue(property), typeof(TProperty)) ?? throw new InvalidOperationException("Unable to find target value");
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information