Fix optimized DP setter codegen for 'string' properties#794
Open
Sergio0694 wants to merge 1 commit intomainfrom
Open
Fix optimized DP setter codegen for 'string' properties#794Sergio0694 wants to merge 1 commit intomainfrom
Sergio0694 wants to merge 1 commit intomainfrom
Conversation
XamlBindingHelper.SetPropertyFromString does not handle 'null' or empty strings correctly, so for 'string' typed dependency properties, fall back to SetValue in those cases and only call the optimized helper for non-empty strings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| { | ||
| writer.Write($$""" | ||
|
|
||
| if (value is null || value.Length == 0) |
Member
There was a problem hiding this comment.
Suggested change
| if (value is null || value.Length == 0) | |
| if (string.IsNullOrEmpty(value)) |
QQ: I know it's equivalent but would using the string helper be clearer/more efficient in anyway? (i.e. would it be optimized by the compiler anyway vs. the function overhead?)
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.
Follow-up to #792.
The optimized codegen for generated dependency property setters introduced in #792 calls
XamlBindingHelper.SetProperty*directly, but it turns out thatXamlBindingHelper.SetPropertyFromStringdoes not work correctly when the value isnullor an empty string. To work around this, the generator now special-casesstringproperties and emits this code instead of an unconditional helper call:This is applied to both the local-caching and no-caching setter paths.
The existing unit tests covering
stringandstring?dependency properties (including the parameterized rows inSingleProperty_MultipleTypes_WithNoCaching_DefaultValueIsOptimizedandSingleProperty_WithCustomMetadataType_WithNoCaching, plus the explicitSingleProperty_String_WithLocalCachetest and others) have been updated to reflect the new generated code, so coverage for both setter paths is preserved.