Skip to content

Commit

Permalink
perf: Improve DependencyPropertyDetails performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 19, 2021
1 parent e84146f commit 640a543
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 58 deletions.
40 changes: 40 additions & 0 deletions src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,13 @@ public void When_Set_With_Both_Style_And_LocalValue()
#endif
}

[TestMethod]
public void When_DefaultValueOverride()
{
var SUT = new MyDependencyObjectWithDefaultValueOverride();
Assert.AreEqual(42, SUT.GetValue(MyDependencyObjectWithDefaultValueOverride.MyPropertyProperty));
}

private class MyDependencyObject : FrameworkElement
{
internal static readonly DependencyProperty PropAProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -1790,5 +1797,38 @@ private void OnMyNullableChanged(DependencyPropertyChangedEventArgs e)

}

partial class MyDependencyObjectWithDefaultValueOverride : DependencyObject
{
public MyDependencyObjectWithDefaultValueOverride()
{
this.RegisterDefaultValueProvider(OnProvideDefaultValue);
}

private bool OnProvideDefaultValue(DependencyProperty property, out object defaultValue)
{
if(property == MyPropertyProperty)
{
defaultValue = 42;

return true;
}

defaultValue = null;
return false;
}

public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}

// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(MyDependencyObjectWithDefaultValueOverride), new PropertyMetadata(0));

}


#endregion
}
Loading

0 comments on commit 640a543

Please sign in to comment.