diff --git a/src/Uno.UI.RuntimeTests/Tests/Uno_Helpers/Given_DependencyPropertyHelper.cs b/src/Uno.UI.RuntimeTests/Tests/Uno_Helpers/Given_DependencyPropertyHelper.cs index 9d0a6bdcc8..5da739a508 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Uno_Helpers/Given_DependencyPropertyHelper.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Uno_Helpers/Given_DependencyPropertyHelper.cs @@ -122,7 +122,7 @@ public partial class Given_DependencyPropertyHelper var property = TestClass.TestProperty; // Act - var propertyType = DependencyPropertyHelper.GetPropertyType(property); + var propertyType = DependencyPropertyHelper.GetValueType(property); // Assert propertyType.Should().Be(typeof(string)); @@ -135,7 +135,7 @@ public partial class Given_DependencyPropertyHelper var property = TestClass.TestProperty; // Act - var (valueType, ownerType, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetPropertyDetails(property); + var (valueType, ownerType, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetDetails(property); // Assert using var _ = new AssertionScope(); @@ -155,7 +155,7 @@ public partial class Given_DependencyPropertyHelper var property = UIElement.DataContextProperty; // Act - var (valueType, _, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetPropertyDetails(property); + var (valueType, _, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetDetails(property); // Assert using var _ = new AssertionScope(); @@ -175,7 +175,7 @@ public partial class Given_DependencyPropertyHelper var property = Grid.RowProperty; // Act - var (valueType, ownerType, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetPropertyDetails(property); + var (valueType, ownerType, name, isTypeNullable, isAttached, inInherited, defaultValue) = DependencyPropertyHelper.GetDetails(property); // Assert using var _ = new AssertionScope(); @@ -208,7 +208,7 @@ public partial class Given_DependencyPropertyHelper // Assert defaultValue.Should().Be("TestValue"); } - + [TestMethod] public void When_GetDefaultUnsetValue_FromStyle() { @@ -223,7 +223,7 @@ public partial class Given_DependencyPropertyHelper unsetValue.Should().Be("StyledTestValue"); precedence.Should().Be(DependencyPropertyValuePrecedences.ExplicitStyle); } - + [TestMethod] public void When_GetDefaultUnsetValue() { diff --git a/src/Uno.UI/UI/Xaml/Internal/DependencyPropertyHelper.cs b/src/Uno.UI/UI/Xaml/Internal/DependencyPropertyHelper.cs index 13b18bf3d6..1df1608380 100644 --- a/src/Uno.UI/UI/Xaml/Internal/DependencyPropertyHelper.cs +++ b/src/Uno.UI/UI/Xaml/Internal/DependencyPropertyHelper.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.UI.Xaml.Controls; -using Uno.Extensions; namespace Uno.UI.Xaml.Core; @@ -92,13 +91,13 @@ internal static class DependencyPropertyHelper /// /// Get the value type of the property. /// - public static Type GetPropertyType(DependencyProperty dependencyProperty) + public static Type GetValueType(DependencyProperty dependencyProperty) => dependencyProperty.Type; /// /// Get the name of the property. /// - public static string GetPropertyName(DependencyProperty dependencyProperty) + public static string GetName(DependencyProperty dependencyProperty) => dependencyProperty.Name; /// @@ -108,13 +107,13 @@ internal static class DependencyPropertyHelper /// This is the property that defines the property, not the type that uses it. /// It may also be overridden by a derived type. /// - public static Type GetPropertyOwnerType(DependencyProperty dependencyProperty) + public static Type GetOwnerType(DependencyProperty dependencyProperty) => dependencyProperty.OwnerType; /// /// Get whether the property is an Attached Property. /// - public static bool GetPropertyIsAttached(DependencyProperty dependencyProperty) + public static bool GetIsAttached(DependencyProperty dependencyProperty) => dependencyProperty.IsAttached; /// @@ -148,18 +147,18 @@ internal static class DependencyPropertyHelper return (valueFromImplicitStyle, DependencyPropertyValuePrecedences.ImplicitStyle); } - if(obj is IDependencyObjectStoreProvider { Store: { } store } && store.GetPropertyDetails(dependencyProperty) is { } details) + if (obj is IDependencyObjectStoreProvider { Store: { } store } && store.GetPropertyDetails(dependencyProperty) is { } details) { // 3rd: Check inherited value var inheritedValue = details.GetInheritedValue(); - if(inheritedValue != DependencyProperty.UnsetValue) + if (inheritedValue != DependencyProperty.UnsetValue) { return (details.GetInheritedValue(), DependencyPropertyValuePrecedences.Inheritance); } // 4th: Check default value var defaultValue = store.GetDefaultValue(dependencyProperty); - if(defaultValue != DependencyProperty.UnsetValue) + if (defaultValue != DependencyProperty.UnsetValue) { return (defaultValue, DependencyPropertyValuePrecedences.DefaultValue); } @@ -186,20 +185,25 @@ internal static class DependencyPropertyHelper /// /// Get if the property value is inherited through the visual tree. /// - public static bool GetPropertyIsInherited(DependencyProperty dependencyProperty) + public static bool GetIsInherited(DependencyProperty dependencyProperty) => dependencyProperty.GetMetadata(dependencyProperty.OwnerType) is FrameworkPropertyMetadata metadata && metadata.Options.HasFlag(FrameworkPropertyMetadataOptions.Inherits); /// /// Get the multiple aspects of a given property at the same time. /// - public static (Type ValueType, Type OwnerType, string Name, bool IsTypeNullable, bool IsAttached, bool IsInherited, object? defaultValue) GetPropertyDetails( + public static (Type ValueType, Type OwnerType, string Name, bool IsTypeNullable, bool IsAttached, bool IsInherited, object? defaultValue) GetDetails( DependencyProperty property) - => (property.Type, + { + var propertyMetadata = property.GetMetadata(property.OwnerType); + + return (property.Type, property.OwnerType, property.Name, property.IsTypeNullable, property.IsAttached, - property.GetMetadata(property.OwnerType) is FrameworkPropertyMetadata metadata && metadata.Options.HasFlag(FrameworkPropertyMetadataOptions.Inherits), - property.GetMetadata(property.OwnerType)?.DefaultValue); + propertyMetadata is FrameworkPropertyMetadata metadata && + metadata.Options.HasFlag(FrameworkPropertyMetadataOptions.Inherits), + propertyMetadata?.DefaultValue); + } }