Skip to content

Commit

Permalink
chore: Adjust method names
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Sep 13, 2024
1 parent 844b8e2 commit 25c3646
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void When_GetPropertyType()
var property = TestClass.TestProperty;

// Act
var propertyType = DependencyPropertyHelper.GetPropertyType(property);
var propertyType = DependencyPropertyHelper.GetValueType(property);

// Assert
propertyType.Should().Be(typeof(string));
Expand All @@ -135,7 +135,7 @@ public void When_GetPropertyDetails()
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();
Expand All @@ -155,7 +155,7 @@ public void When_GetPropertyDetails_DataContext()
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();
Expand All @@ -175,7 +175,7 @@ public void When_GetPropertyDetails_Attached()
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();
Expand Down Expand Up @@ -208,7 +208,7 @@ public void When_GetDefaultValue_Derived()
// Assert
defaultValue.Should().Be("TestValue");
}

[TestMethod]
public void When_GetDefaultUnsetValue_FromStyle()
{
Expand All @@ -223,7 +223,7 @@ public void When_GetDefaultUnsetValue_FromStyle()
unsetValue.Should().Be("StyledTestValue");
precedence.Should().Be(DependencyPropertyValuePrecedences.ExplicitStyle);
}

[TestMethod]
public void When_GetDefaultUnsetValue()
{
Expand Down
30 changes: 17 additions & 13 deletions src/Uno.UI/UI/Xaml/Internal/DependencyPropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.UI.Xaml.Controls;
using Uno.Extensions;

namespace Uno.UI.Xaml.Core;

Expand Down Expand Up @@ -92,13 +91,13 @@ public static bool TryGetDependencyPropertiesForType(
/// <summary>
/// Get the value type of the property.
/// </summary>
public static Type GetPropertyType(DependencyProperty dependencyProperty)
public static Type GetValueType(DependencyProperty dependencyProperty)
=> dependencyProperty.Type;

/// <summary>
/// Get the name of the property.
/// </summary>
public static string GetPropertyName(DependencyProperty dependencyProperty)
public static string GetName(DependencyProperty dependencyProperty)
=> dependencyProperty.Name;

/// <summary>
Expand All @@ -108,13 +107,13 @@ public static string GetPropertyName(DependencyProperty dependencyProperty)
/// This is the property that defines the property, not the type that uses it.
/// It may also be overridden by a derived type.
/// </remarks>
public static Type GetPropertyOwnerType(DependencyProperty dependencyProperty)
public static Type GetOwnerType(DependencyProperty dependencyProperty)
=> dependencyProperty.OwnerType;

/// <summary>
/// Get whether the property is an Attached Property.
/// </summary>
public static bool GetPropertyIsAttached(DependencyProperty dependencyProperty)
public static bool GetIsAttached(DependencyProperty dependencyProperty)
=> dependencyProperty.IsAttached;

/// <summary>
Expand Down Expand Up @@ -148,18 +147,18 @@ public static (object? value, DependencyPropertyValuePrecedences precedence) Get
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);
}
Expand All @@ -186,20 +185,25 @@ public static void SetValueForPrecedence(
/// <summary>
/// Get if the property value is inherited through the visual tree.
/// </summary>
public static bool GetPropertyIsInherited(DependencyProperty dependencyProperty)
public static bool GetIsInherited(DependencyProperty dependencyProperty)
=> dependencyProperty.GetMetadata(dependencyProperty.OwnerType) is FrameworkPropertyMetadata metadata
&& metadata.Options.HasFlag(FrameworkPropertyMetadataOptions.Inherits);

/// <summary>
/// Get the multiple aspects of a given property at the same time.
/// </summary>
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);
}
}

0 comments on commit 25c3646

Please sign in to comment.