Browse Source

Remove unneeded classes/methods.

refactor/bindingexpressions-in-valuestore
Steven Kirk 3 years ago
parent
commit
d6fc56fe0e
  1. 39
      src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs
  2. 18
      src/Avalonia.Base/PropertyStore/UntypedValueUtils.cs
  3. 60
      src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs

39
src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs

@ -1,39 +0,0 @@
using System;
using Avalonia.Data;
namespace Avalonia.PropertyStore
{
/// <summary>
/// An <see cref="IValueEntry"/> that holds a binding whose source observable and target
/// property are both untyped.
/// </summary>
internal class UntypedBindingEntry : BindingEntryBase<object?, object?>
{
private readonly Func<object?, bool>? _validate;
public UntypedBindingEntry(
AvaloniaObject target,
ValueFrame frame,
AvaloniaProperty property,
IObservable<object?> source)
: base(target, frame, property, source)
{
_validate = ((IStyledPropertyAccessor)property).ValidateValue;
}
protected override BindingValue<object?> ConvertAndValidate(object? value)
{
return UntypedValueUtils.ConvertAndValidate(value, Property.PropertyType, _validate);
}
protected override BindingValue<object?> ConvertAndValidate(BindingValue<object?> value)
{
throw new NotSupportedException();
}
protected override object? GetDefaultValue(Type ownerType)
{
return ((IStyledPropertyMetadata)Property.GetMetadata(ownerType)).DefaultValue;
}
}
}

18
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<T>(
StyledProperty<T> 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;
}
}
}

60
src/Avalonia.Base/Styling/PropertySetterBindingInstance.cs

@ -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<object?> source)
: base(target, instance, property, source)
{
_target = target;
_mode = mode;
if (mode == BindingMode.TwoWay &&
source is not IObserver<object?>)
{
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<object?>)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<object?>)Source).OnNext(e.NewValue);
}
}
}
}
Loading…
Cancel
Save