SettableNode.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Avalonia.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Avalonia.Data.Core
  8. {
  9. internal abstract class SettableNode : ExpressionNode
  10. {
  11. public bool SetTargetValue(object value, BindingPriority priority)
  12. {
  13. if (ShouldNotSet(value))
  14. {
  15. return true;
  16. }
  17. return SetTargetValueCore(value, priority);
  18. }
  19. private bool ShouldNotSet(object value)
  20. {
  21. if (PropertyType == null)
  22. {
  23. return false;
  24. }
  25. if (PropertyType.IsValueType)
  26. {
  27. return LastValue?.Target != null && LastValue.Target.Equals(value);
  28. }
  29. return LastValue != null && Object.ReferenceEquals(LastValue?.Target, value);
  30. }
  31. protected abstract bool SetTargetValueCore(object value, BindingPriority priority);
  32. public abstract Type PropertyType { get; }
  33. }
  34. }