Optimize codegen for generated dependency property setters#792
Open
Sergio0694 wants to merge 4 commits intomainfrom
Open
Optimize codegen for generated dependency property setters#792Sergio0694 wants to merge 4 commits intomainfrom
Sergio0694 wants to merge 4 commits intomainfrom
Conversation
d4c7c8d to
6a789f1
Compare
Add support for using XamlBindingHelper.SetPropertyFrom* methods to optimize generated dependency property setters. Introduces WellKnownTypeNames.XamlBindingHelper to resolve the fully-qualified type name, adds Execute.GetXamlBindingHelperSetMethodName and Execute.IsObjectSetCallbackImplemented to detect applicable types and user overrides, and wires the chosen method into the generator pipeline. Generation now emits direct XamlBindingHelper calls when available and falls back to boxed SetValue path otherwise. Also update DependencyPropertyInfo to carry the XamlBindingHelperSetMethodName.
Replace manual boxing and SetValue calls with global::Windows.UI.Xaml.Markup.XamlBindingHelper.SetPropertyFrom* calls across the dependency property generator tests. Update DataRow entries to include the target set method name and refactor the test helper to compute the setter body based on an optional setMethodName parameter. Add a new test (SingleProperty_Int32_WithNoCaching_WithObjectSetCallback) covering an int property with an object-based OnNumberSet callback to validate generated code that mixes object set callbacks and optimized XamlBindingHelper setters. Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
6a789f1 to
5187a35
Compare
Replace manual boxing and SetValue call in the generated Name property setter with a call to global::Windows.UI.Xaml.Markup.XamlBindingHelper.SetPropertyFromString(this, NameProperty, value) to avoid temporary object boxing and better align with XAML binding semantics. Also add a missing [TestMethod] attribute to the SingleProperty_Int32_WithNoCaching_WithDefaultValue_WithCallback test so it will be executed.
5187a35 to
f6cda27
Compare
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.
This pull request introduces an optimization to the DependencyPropertyGenerator by leveraging specialized
XamlBindingHelper.SetPropertyFrom*methods for supported property types. This results in more efficient generated code for property setters, while maintaining compatibility with user-defined callbacks and fallback logic for unsupported types. The changes also refactor and extend the generator’s internal APIs to support this feature.Optimized setter generation using XamlBindingHelper:
XamlBindingHelper.SetPropertyFrom*method (e.g.,SetPropertyFromBoolean,SetPropertyFromInt32). If so, it emits a direct call to this method in the generated setter for improved performance. This optimization is skipped if the property type isobjector if the user has implemented a customOn<PropertyName>Set(ref object)callback. [1] [2] [3] [4]API and model extensions to support the optimization:
XamlBindingHelperSetMethodNameproperty to theDependencyPropertyInforecord, and updated the generator pipeline to compute and pass this value. This enables the code generation logic to conditionally emit the optimized setter code. [1] [2] [3]Well-known type name utilities:
XamlBindingHelper(bool useWindowsUIXaml)inWellKnownTypeNames.csto resolve the fully qualified type name forXamlBindingHelper, supporting both Windows and Microsoft UI XAML namespaces.Code generation logic updates:
On<PropertyName>Set(ref object)partial method when the optimization is not used. [1] [2] [3] [4] [5]These changes improve the efficiency of generated dependency property code and maintain backward compatibility for advanced scenarios.