Browse Source

Avoid boxing if property is correct type.

For typed bindings, we'll have an `AvaloniaPropertyChangedEventArgs<T>` where `T` is the same as the type of the `AvaloniaPropertyObservable`. For non-typed bindings we'll have `object` as `T` so use the non-typed `AvaloniaProperty`.
pull/3255/head
Steven Kirk 7 years ago
parent
commit
c2d5f62390
  1. 11
      src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs

11
src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs

@ -44,7 +44,16 @@ namespace Avalonia.Reactive
{
if (e.Property == _property)
{
var newValue = e.Sender.GetValue(e.Property);
T newValue;
if (e is AvaloniaPropertyChangedEventArgs<T> typed)
{
newValue = typed.Sender.GetValue(typed.Property);
}
else
{
newValue = (T)e.Sender.GetValue(e.Property);
}
if (!Equals(newValue, _value))
{

Loading…
Cancel
Save