-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[XC] better support for nullable props and BPs #28550
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
Conversation
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.
Pull Request Overview
This pull request improves support for nullable bindable properties and properties by updating how values are set and unboxed in the IL generation logic. Key changes include:
- Introducing a new local function CanSetValue in SetPropertiesVisitor.cs to encapsulate value setting logic.
- Adjusting the handling of nullable types in the SetValue and CanSetValue routines.
- Updating test cases in Unreported008.xaml.cs and Bz24910.xaml.cs to verify proper handling of nullable types and replacing hard-coded property names with nameof().
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs | Refactors value setting logic with a new local helper and adjusts nullable type handling |
src/Controls/tests/Xaml.UnitTests/Issues/Unreported008.xaml.cs | Adds a new view to test nullable bindable property behavior |
src/Controls/tests/Xaml.UnitTests/Issues/Bz24910.xaml.cs | Updates BindableProperty.Create calls to use nameof(), ensuring consistency |
src/Controls/src/Build.Tasks/VariableDefinitionExtensions.cs | Comments out a branch for unboxing nullable types, likely for future reconsideration |
Files not reviewed (1)
- src/Controls/tests/Xaml.UnitTests/Issues/Unreported008.xaml: Language not supported
Comments suppressed due to low confidence (2)
src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs:1459
- The original code returned the result of an inheritance check for the variable type against bpTypeRef, whereas the new code unconditionally returns false. This change might inadvertently break scenarios where the variable type inherits from bpTypeRef; please verify that the new behavior is intentional.
return false;
src/Controls/src/Build.Tasks/VariableDefinitionExtensions.cs:21
- There is an unused commented code block related to handling System.Nullable`1 types. Consider removing it or adding a clarifying comment if it’s intended to indicate future work to avoid confusion.
// yield return Instruction.Create(OpCodes.Unbox_Any, module.ImportReference(type));
yield return instruction; | ||
if (bpTypeRef.IsValueType) | ||
{ | ||
if ( bpTypeRef.ResolveCached(context.Cache).FullName == "System.Nullable`1" |
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.
this is the main change
792bb9d
to
bbd5372
Compare
@@ -1410,6 +1410,25 @@ static IEnumerable<Instruction> SetBinding(VariableDefinition parent, FieldRefer | |||
|
|||
static bool CanSetValue(FieldReference bpRef, bool attached, INode node, IXmlLineInfo iXmlLineInfo, ILContext context) | |||
{ | |||
static bool CanSetValue (TypeReference bpTypeRef, VariableDefinition varValue, ILContext context, IXmlLineInfo iXmlLineInfo) |
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.
extracting the logic in a local method to run it twice, once on the nullable type, once on the inner type
Description of Change
As requested by @jfversluis: support nullable BPs and props
Issues Fixed
Fixes #28010