Skip to content

Commit

Permalink
Merge pull request #9553 from AvaloniaUI/refactor/remove-interfaces
Browse files Browse the repository at this point in the history
The Great Interface Removal Part I
  • Loading branch information
maxkatz6 committed Nov 29, 2022
2 parents a64f57d + 9825e51 commit ca26912
Show file tree
Hide file tree
Showing 409 changed files with 2,225 additions and 2,713 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ public async Task Start(Visual? from, Visual? to, bool forward, CancellationToke
/// <remarks>
/// Any one of the parameters may be null, but not both.
/// </remarks>
private static IVisual GetVisualParent(IVisual? from, IVisual? to)
private static Visual GetVisualParent(Visual? from, Visual? to)
{
var p1 = (from ?? to)!.VisualParent;
var p2 = (to ?? from)!.VisualParent;
var p1 = (from ?? to)!.GetVisualParent();
var p2 = (to ?? from)!.GetVisualParent();

if (p1 != null && p2 != null && p1 != p2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public IRenderer CreateRenderer(IRenderRoot root) =>
? new CompositingRenderer(root, AndroidPlatform.Compositor)
: AndroidPlatform.Options.UseDeferredRendering
? new DeferredRenderer(root, AvaloniaLocator.Current.GetRequiredService<IRenderLoop>()) { RenderOnlyOnRenderThread = true }
: new ImmediateRenderer(root);
: new ImmediateRenderer((Visual)root);

public virtual void Hide()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Base/Animation/PageSlide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public virtual async Task Start(Visual? from, Visual? to, bool forward, Cancella
/// <remarks>
/// Any one of the parameters may be null, but not both.
/// </remarks>
protected static IVisual GetVisualParent(IVisual? from, IVisual? to)
protected static Visual GetVisualParent(Visual? from, Visual? to)
{
var p1 = (from ?? to)!.VisualParent;
var p2 = (to ?? from)!.VisualParent;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Base/AttachedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AttachedProperty(
/// </summary>
/// <typeparam name="TOwner">The owner type.</typeparam>
/// <returns>The property.</returns>
public new AttachedProperty<TValue> AddOwner<TOwner>() where TOwner : IAvaloniaObject
public new AttachedProperty<TValue> AddOwner<TOwner>() where TOwner : AvaloniaObject
{
AvaloniaPropertyRegistry.Instance.Register(typeof(TOwner), this);
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Base/AvaloniaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Avalonia
/// <remarks>
/// This class is analogous to DependencyObject in WPF.
/// </remarks>
public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged
public class AvaloniaObject : IAvaloniaObjectDebug, INotifyPropertyChanged
{
private readonly ValueStore _values;
private AvaloniaObject? _inheritanceParent;
Expand Down
100 changes: 38 additions & 62 deletions src/Avalonia.Base/AvaloniaObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IBinding ToBinding<T>(this IObservable<T> source)
/// <remarks>
/// The subscription to <paramref name="o"/> is created using a weak reference.
/// </remarks>
public static IObservable<object?> GetObservable(this IAvaloniaObject o, AvaloniaProperty property)
public static IObservable<object?> GetObservable(this AvaloniaObject o, AvaloniaProperty property)
{
return new AvaloniaPropertyObservable<object?>(
o ?? throw new ArgumentNullException(nameof(o)),
Expand All @@ -56,7 +56,7 @@ public static IBinding ToBinding<T>(this IObservable<T> source)
/// <remarks>
/// The subscription to <paramref name="o"/> is created using a weak reference.
/// </remarks>
public static IObservable<T> GetObservable<T>(this IAvaloniaObject o, AvaloniaProperty<T> property)
public static IObservable<T> GetObservable<T>(this AvaloniaObject o, AvaloniaProperty<T> property)
{
return new AvaloniaPropertyObservable<T>(
o ?? throw new ArgumentNullException(nameof(o)),
Expand All @@ -76,7 +76,7 @@ public static IObservable<T> GetObservable<T>(this IAvaloniaObject o, AvaloniaPr
/// The subscription to <paramref name="o"/> is created using a weak reference.
/// </remarks>
public static IObservable<BindingValue<object?>> GetBindingObservable(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty property)
{
return new AvaloniaPropertyBindingObservable<object?>(
Expand All @@ -98,7 +98,7 @@ public static IObservable<T> GetObservable<T>(this IAvaloniaObject o, AvaloniaPr
/// The subscription to <paramref name="o"/> is created using a weak reference.
/// </remarks>
public static IObservable<BindingValue<T>> GetBindingObservable<T>(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty<T> property)
{
return new AvaloniaPropertyBindingObservable<T>(
Expand All @@ -115,11 +115,11 @@ public static IObservable<BindingValue<T>> GetBindingObservable<T>(
/// <param name="property">The property.</param>
/// <returns>
/// An observable which when subscribed pushes the property changed event args
/// each time a <see cref="IAvaloniaObject.PropertyChanged"/> event is raised
/// each time a <see cref="AvaloniaObject.PropertyChanged"/> event is raised
/// for the specified property.
/// </returns>
public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedObservable(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty property)
{
return new AvaloniaPropertyChangedObservable(
Expand All @@ -140,7 +140,7 @@ public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedOb
/// property.
/// </returns>
public static ISubject<object?> GetSubject(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty property,
BindingPriority priority = BindingPriority.LocalValue)
{
Expand All @@ -163,7 +163,7 @@ public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedOb
/// property.
/// </returns>
public static ISubject<T> GetSubject<T>(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty<T> property,
BindingPriority priority = BindingPriority.LocalValue)
{
Expand All @@ -185,7 +185,7 @@ public static ISubject<T> GetSubject<T>(
/// property.
/// </returns>
public static ISubject<BindingValue<object?>> GetBindingSubject(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty property,
BindingPriority priority = BindingPriority.LocalValue)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ public static ISubject<T> GetSubject<T>(
/// property.
/// </returns>
public static ISubject<BindingValue<T>> GetBindingSubject<T>(
this IAvaloniaObject o,
this AvaloniaObject o,
AvaloniaProperty<T> property,
BindingPriority priority = BindingPriority.LocalValue)
{
Expand All @@ -241,7 +241,7 @@ public static ISubject<BindingValue<T>> GetBindingSubject<T>(
/// A disposable which can be used to terminate the binding.
/// </returns>
public static IDisposable Bind<T>(
this IAvaloniaObject target,
this AvaloniaObject target,
AvaloniaProperty<T> property,
IObservable<BindingValue<T>> source,
BindingPriority priority = BindingPriority.LocalValue)
Expand All @@ -250,17 +250,12 @@ public static IDisposable Bind<T>(
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));

if (target is AvaloniaObject ao)
return property switch
{
return property switch
{
StyledPropertyBase<T> styled => ao.Bind(styled, source, priority),
DirectPropertyBase<T> direct => ao.Bind(direct, source),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
};
}

throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported.");
StyledPropertyBase<T> styled => target.Bind(styled, source, priority),
DirectPropertyBase<T> direct => target.Bind(direct, source),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
};
}

/// <summary>
Expand All @@ -274,22 +269,17 @@ public static IDisposable Bind<T>(
/// A disposable which can be used to terminate the binding.
/// </returns>
public static IDisposable Bind<T>(
this IAvaloniaObject target,
this AvaloniaObject target,
AvaloniaProperty<T> property,
IObservable<T> source,
BindingPriority priority = BindingPriority.LocalValue)
{
if (target is AvaloniaObject ao)
return property switch
{
return property switch
{
StyledPropertyBase<T> styled => ao.Bind(styled, source, priority),
DirectPropertyBase<T> direct => ao.Bind(direct, source),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
};
}

throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported.");
StyledPropertyBase<T> styled => target.Bind(styled, source, priority),
DirectPropertyBase<T> direct => target.Bind(direct, source),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
};
}

/// <summary>
Expand All @@ -306,7 +296,7 @@ public static IDisposable Bind<T>(
/// </param>
/// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
public static IDisposable Bind(
this IAvaloniaObject target,
this AvaloniaObject target,
AvaloniaProperty property,
IBinding binding,
object? anchor = null)
Expand Down Expand Up @@ -340,23 +330,17 @@ public static IDisposable Bind(
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
public static T GetValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> property)
public static T GetValue<T>(this AvaloniaObject target, AvaloniaProperty<T> property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));

if (target is AvaloniaObject ao)
return property switch
{
return property switch
{
StyledPropertyBase<T> styled => ao.GetValue(styled),
DirectPropertyBase<T> direct => ao.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};

}

throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported.");
StyledPropertyBase<T> styled => target.GetValue(styled),
DirectPropertyBase<T> direct => target.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};
}

/// <summary>
Expand All @@ -372,15 +356,13 @@ public static T GetValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> pro
/// For direct properties returns the current value of the property.
/// </remarks>
public static object? GetBaseValue(
this IAvaloniaObject target,
this AvaloniaObject target,
AvaloniaProperty property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));

if (target is AvaloniaObject ao)
return property.RouteGetBaseValue(ao);
throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported.");
return property.RouteGetBaseValue(target);
}

/// <summary>
Expand All @@ -396,24 +378,18 @@ public static T GetValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> pro
/// For direct properties returns the current value of the property.
/// </remarks>
public static Optional<T> GetBaseValue<T>(
this IAvaloniaObject target,
this AvaloniaObject target,
AvaloniaProperty<T> property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));

if (target is AvaloniaObject ao)
return property switch
{
return property switch
{
StyledPropertyBase<T> styled => ao.GetBaseValue(styled),
DirectPropertyBase<T> direct => ao.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};

}

throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported.");
StyledPropertyBase<T> styled => target.GetBaseValue(styled),
DirectPropertyBase<T> direct => target.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};
}

/// <summary>
Expand Down Expand Up @@ -474,7 +450,7 @@ public BindingAdaptor(IObservable<object?> source)
}

public InstancedBinding? Initiate(
IAvaloniaObject target,
AvaloniaObject target,
AvaloniaProperty? targetProperty,
object? anchor = null,
bool enableDataValidation = false)
Expand Down
22 changes: 11 additions & 11 deletions src/Avalonia.Base/AvaloniaProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected AvaloniaProperty(
Type valueType,
Type ownerType,
AvaloniaPropertyMetadata metadata,
Action<IAvaloniaObject, bool>? notifying = null)
Action<AvaloniaObject, bool>? notifying = null)
{
_ = name ?? throw new ArgumentNullException(nameof(name));

Expand Down Expand Up @@ -145,7 +145,7 @@ protected AvaloniaProperty(
/// will be true before the property change notifications are sent and false afterwards. This
/// callback is intended to support Control.IsDataContextChanging.
/// </remarks>
public Action<IAvaloniaObject, bool>? Notifying { get; }
public Action<AvaloniaObject, bool>? Notifying { get; }

/// <summary>
/// Gets the integer ID that represents this property.
Expand Down Expand Up @@ -238,9 +238,9 @@ public static StyledProperty<TValue> Register<TOwner, TValue>(
bool inherits = false,
BindingMode defaultBindingMode = BindingMode.OneWay,
Func<TValue, bool>? validate = null,
Func<IAvaloniaObject, TValue, TValue>? coerce = null,
Action<IAvaloniaObject, bool>? notifying = null)
where TOwner : IAvaloniaObject
Func<AvaloniaObject, TValue, TValue>? coerce = null,
Action<AvaloniaObject, bool>? notifying = null)
where TOwner : AvaloniaObject
{
_ = name ?? throw new ArgumentNullException(nameof(name));

Expand Down Expand Up @@ -279,8 +279,8 @@ public static AttachedProperty<TValue> RegisterAttached<TOwner, THost, TValue>(
bool inherits = false,
BindingMode defaultBindingMode = BindingMode.OneWay,
Func<TValue, bool>? validate = null,
Func<IAvaloniaObject, TValue, TValue>? coerce = null)
where THost : IAvaloniaObject
Func<AvaloniaObject, TValue, TValue>? coerce = null)
where THost : AvaloniaObject
{
_ = name ?? throw new ArgumentNullException(nameof(name));

Expand Down Expand Up @@ -316,8 +316,8 @@ public static AttachedProperty<TValue> RegisterAttached<THost, TValue>(
bool inherits = false,
BindingMode defaultBindingMode = BindingMode.OneWay,
Func<TValue, bool>? validate = null,
Func<IAvaloniaObject, TValue, TValue>? coerce = null)
where THost : IAvaloniaObject
Func<AvaloniaObject, TValue, TValue>? coerce = null)
where THost : AvaloniaObject
{
_ = name ?? throw new ArgumentNullException(nameof(name));

Expand Down Expand Up @@ -354,7 +354,7 @@ public static DirectProperty<TOwner, TValue> RegisterDirect<TOwner, TValue>(
TValue unsetValue = default!,
BindingMode defaultBindingMode = BindingMode.OneWay,
bool enableDataValidation = false)
where TOwner : IAvaloniaObject
where TOwner : AvaloniaObject
{
_ = name ?? throw new ArgumentNullException(nameof(name));
_ = getter ?? throw new ArgumentNullException(nameof(getter));
Expand Down Expand Up @@ -415,7 +415,7 @@ public override int GetHashCode()
/// <returns>
/// The property metadata.
/// </returns>
public AvaloniaPropertyMetadata GetMetadata<T>() where T : IAvaloniaObject
public AvaloniaPropertyMetadata GetMetadata<T>() where T : AvaloniaObject
{
return GetMetadata(typeof(T));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Avalonia
public abstract class AvaloniaPropertyChangedEventArgs : EventArgs
{
public AvaloniaPropertyChangedEventArgs(
IAvaloniaObject sender,
AvaloniaObject sender,
BindingPriority priority)
{
Sender = sender;
Expand All @@ -18,7 +18,7 @@ public AvaloniaPropertyChangedEventArgs(
}

internal AvaloniaPropertyChangedEventArgs(
IAvaloniaObject sender,
AvaloniaObject sender,
BindingPriority priority,
bool isEffectiveValueChange)
{
Expand All @@ -31,7 +31,7 @@ internal AvaloniaPropertyChangedEventArgs(
/// Gets the <see cref="AvaloniaObject"/> that the property changed on.
/// </summary>
/// <value>The sender object.</value>
public IAvaloniaObject Sender { get; }
public AvaloniaObject Sender { get; }

/// <summary>
/// Gets the property that changed.
Expand Down
Loading

0 comments on commit ca26912

Please sign in to comment.