From d6fc56fe0e7f181d12cd0089a3b99ccae74b02fe Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 24 Nov 2023 16:27:42 +0100 Subject: [PATCH] Remove unneeded classes/methods. --- .../PropertyStore/UntypedBindingEntry.cs | 39 ------------ .../PropertyStore/UntypedValueUtils.cs | 18 ------ .../Styling/PropertySetterBindingInstance.cs | 60 ------------------- 3 files changed, 117 deletions(-) delete mode 100644 src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs delete mode 100644 src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs diff --git a/src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs b/src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs deleted file mode 100644 index e3a7607479..0000000000 --- a/src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Avalonia.Data; - -namespace Avalonia.PropertyStore -{ - /// - /// An that holds a binding whose source observable and target - /// property are both untyped. - /// - internal class UntypedBindingEntry : BindingEntryBase - { - private readonly Func? _validate; - - public UntypedBindingEntry( - AvaloniaObject target, - ValueFrame frame, - AvaloniaProperty property, - IObservable source) - : base(target, frame, property, source) - { - _validate = ((IStyledPropertyAccessor)property).ValidateValue; - } - - protected override BindingValue ConvertAndValidate(object? value) - { - return UntypedValueUtils.ConvertAndValidate(value, Property.PropertyType, _validate); - } - - protected override BindingValue ConvertAndValidate(BindingValue value) - { - throw new NotSupportedException(); - } - - protected override object? GetDefaultValue(Type ownerType) - { - return ((IStyledPropertyMetadata)Property.GetMetadata(ownerType)).DefaultValue; - } - } -} diff --git a/src/Avalonia.Base/PropertyStore/UntypedValueUtils.cs b/src/Avalonia.Base/PropertyStore/UntypedValueUtils.cs index 4912ec1d81..fb22e46794 100644 --- a/src/Avalonia.Base/PropertyStore/UntypedValueUtils.cs +++ b/src/Avalonia.Base/PropertyStore/UntypedValueUtils.cs @@ -23,23 +23,5 @@ namespace Avalonia.PropertyStore return v; } - - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = TrimmingMessages.ImplicitTypeConversionSupressWarningMessage)] - public static bool TryConvertAndValidate( - StyledProperty property, - object? value, - [MaybeNullWhen(false)] out T result) - { - if (TypeUtilities.TryConvertImplicit(typeof(T), value, out var v)) - { - result = (T)v!; - - if (property.ValidateValue?.Invoke(result) != false) - return true; - } - - result = default; - return false; - } } } diff --git a/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs b/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs deleted file mode 100644 index be5a999771..0000000000 --- a/src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using Avalonia.Data; -using Avalonia.PropertyStore; - -namespace Avalonia.Styling -{ - internal class PropertySetterBindingInstance : UntypedBindingEntry, ISetterInstance - { - private readonly AvaloniaObject _target; - private readonly BindingMode _mode; - - public PropertySetterBindingInstance( - AvaloniaObject target, - StyleInstance instance, - AvaloniaProperty property, - BindingMode mode, - IObservable source) - : base(target, instance, property, source) - { - _target = target; - _mode = mode; - - if (mode == BindingMode.TwoWay && - source is not IObserver) - { - throw new NotSupportedException( - "Attempting to bind two-way with a binding source which doesn't support it."); - } - } - - public override void Unsubscribe() - { - _target.PropertyChanged -= PropertyChanged; - base.Unsubscribe(); - } - - protected override void Start(bool produceValue) - { - if (!IsSubscribed) - { - if (_mode == BindingMode.TwoWay) - { - var observer = (IObserver)Source; - _target.PropertyChanged += PropertyChanged; - } - - base.Start(produceValue); - } - } - - private void PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) - { - if (e.Property == Property && e.Priority >= BindingPriority.LocalValue) - { - if (Frame.Owner is not null && !Frame.Owner.IsEvaluating) - ((IObserver)Source).OnNext(e.NewValue); - } - } - } -}