You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Constants/WellKnownTypeNames.cs
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -94,4 +94,15 @@ public static string CreateDefaultValueCallback(bool useWindowsUIXaml)
Copy file name to clipboardExpand all lines: components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/DependencyPropertyGenerator.Execute.cs
// If the default value is not what the default field value would be, add an initializer
728
800
if(propertyInfo.DefaultValueis not (DependencyPropertyDefaultValue.Null or DependencyPropertyDefaultValue.Default or DependencyPropertyDefaultValue.Callback))
/// <summary>Executes the logic for when the <see langword="set"/> accessor <see cref="{propertyInfo.PropertyName}"/> is invoked</summary>
831
-
/// <param name="propertyValue">The boxed property value that has been produced before assigning to <see cref="{propertyInfo.PropertyName}Property"/>.</param>
832
-
/// <remarks>This method is invoked on the boxed value that is about to be passed to <see cref="SetValue"/> on <see cref="{propertyInfo.PropertyName}Property"/>.</remarks>
/// <summary>Executes the logic for when the <see langword="set"/> accessor <see cref="{propertyInfo.PropertyName}"/> is invoked</summary>
929
+
/// <param name="propertyValue">The boxed property value that has been produced before assigning to <see cref="{propertyInfo.PropertyName}Property"/>.</param>
930
+
/// <remarks>This method is invoked on the boxed value that is about to be passed to <see cref="SetValue"/> on <see cref="{propertyInfo.PropertyName}Property"/>.</remarks>
Copy file name to clipboardExpand all lines: components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/DependencyPropertyGenerator.cs
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,26 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
107
107
108
108
token.ThrowIfCancellationRequested();
109
109
110
+
// Get the optimized XamlBindingHelper method name for the property type, if applicable.
111
+
// This is only used when the property type is not 'object' (which would gain nothing),
112
+
// and the user hasn't provided their own 'On<PROPERTY_NAME>Set(ref object)' implementation.
Copy file name to clipboardExpand all lines: components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Models/DependencyPropertyInfo.cs
/// <param name="IsSharedPropertyChangedCallbackImplemented">Indicates whether the WinRT-based shared property changed callback is implemented.</param>
27
27
/// <param name="IsAdditionalTypesGenerationSupported">Indicates whether additional types can be generated.</param>
28
28
/// <param name="UseWindowsUIXaml">Whether to use the UWP XAML or WinUI 3 XAML namespaces.</param>
29
+
/// <param name="XamlBindingHelperSetMethodName">The name of the <c>XamlBindingHelper.SetPropertyFrom*</c> method to use for optimized setters, if available.</param>
29
30
/// <param name="StaticFieldAttributes">The attributes to emit on the generated static field, if any.</param>
30
31
internalsealedrecordDependencyPropertyInfo(
31
32
HierarchyInfoHierarchy,
@@ -44,4 +45,5 @@ internal sealed record DependencyPropertyInfo(
0 commit comments