From 825fcfab31f8363c1e0d5755472355616987032b Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Mon, 15 Aug 2022 14:00:49 +0300 Subject: [PATCH] Remove obsolete members from Avalonia.Base namespace --- src/Avalonia.Base/Animation/Animation.cs | 17 -- .../Animators/SolidColorBrushAnimator.cs | 13 -- src/Avalonia.Base/AvaloniaObjectExtensions.cs | 35 ---- src/Avalonia.Base/AvaloniaProperty`1.cs | 15 -- .../Collections/AvaloniaListExtensions.cs | 15 -- src/Avalonia.Base/DirectPropertyBase.cs | 15 -- src/Avalonia.Base/EnumExtensions.cs | 4 - .../Interactivity/RoutedEvent.cs | 18 -- src/Avalonia.Base/Layout/ILayoutManager.cs | 11 - src/Avalonia.Base/Layout/LayoutManager.cs | 11 - src/Avalonia.Base/Layout/Layoutable.cs | 28 --- src/Avalonia.Base/Media/Imaging/Bitmap.cs | 16 -- .../Media/Imaging/WriteableBitmap.cs | 14 +- src/Avalonia.Base/Utilities/WeakObservable.cs | 25 --- .../Utilities/WeakSubscriptionManager.cs | 193 ------------------ src/Avalonia.Base/Visual.cs | 16 -- .../VisualTree/IVisualTreeHost.cs | 19 -- src/Avalonia.Controls/Primitives/Popup.cs | 9 +- src/Avalonia.Controls/Remote/RemoteWidget.cs | 2 - src/Avalonia.X11/X11IconLoader.cs | 2 - .../Collections/AvaloniaListExtenionsTests.cs | 155 -------------- .../WeakSubscriptionManagerTests.cs | 70 ------- .../Avalonia.RenderTests/Media/BitmapTests.cs | 2 - 23 files changed, 2 insertions(+), 703 deletions(-) delete mode 100644 src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs delete mode 100644 src/Avalonia.Base/VisualTree/IVisualTreeHost.cs delete mode 100644 tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs delete mode 100644 tests/Avalonia.Base.UnitTests/WeakSubscriptionManagerTests.cs diff --git a/src/Avalonia.Base/Animation/Animation.cs b/src/Avalonia.Base/Animation/Animation.cs index 03b2d17e44..6bb06367de 100644 --- a/src/Avalonia.Base/Animation/Animation.cs +++ b/src/Avalonia.Base/Animation/Animation.cs @@ -172,23 +172,6 @@ namespace Avalonia.Animation set { SetAndRaise(SpeedRatioProperty, ref _speedRatio, value); } } - /// - /// Obsolete: Do not use this property, use instead. - /// - /// - [Obsolete("This property has been superceded by IterationCount.")] - public string RepeatCount - { - get { return IterationCount.ToString(); } - set - { - var val = value.ToUpper(); - val = val.Replace("LOOP", "INFINITE"); - val = val.Replace("NONE", "1"); - IterationCount = IterationCount.Parse(val); - } - } - /// /// Gets the children of the . /// diff --git a/src/Avalonia.Base/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Base/Animation/Animators/SolidColorBrushAnimator.cs index b87b2681d6..9256c7be5e 100644 --- a/src/Avalonia.Base/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Base/Animation/Animators/SolidColorBrushAnimator.cs @@ -37,17 +37,4 @@ namespace Avalonia.Animation.Animators } } - [Obsolete("Use ISolidColorBrushAnimator instead")] - public class SolidColorBrushAnimator : Animator - { - public override SolidColorBrush? Interpolate(double progress, SolidColorBrush? oldValue, SolidColorBrush? newValue) - { - if (oldValue is null || newValue is null) - { - return progress >= 0.5 ? newValue : oldValue; - } - - return new SolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValue.Color, newValue.Color)); - } - } } diff --git a/src/Avalonia.Base/AvaloniaObjectExtensions.cs b/src/Avalonia.Base/AvaloniaObjectExtensions.cs index 134e3b2ac7..2d7bab6cd6 100644 --- a/src/Avalonia.Base/AvaloniaObjectExtensions.cs +++ b/src/Avalonia.Base/AvaloniaObjectExtensions.cs @@ -468,41 +468,6 @@ namespace Avalonia }); } - /// - /// Subscribes to a property changed notifications for changes that originate from a - /// . - /// - /// The type of the property change sender. - /// The property changed observable. - /// Given a TTarget, returns the handler. - /// A disposable that can be used to terminate the subscription. - [Obsolete("Use overload taking Action.")] - public static IDisposable AddClassHandler( - this IObservable observable, - Func> handler) - where TTarget : class - { - return observable.Subscribe(e => SubscribeAdapter(e, handler)); - } - - /// - /// Observer method for . - /// - /// The sender type to accept. - /// The event args. - /// Given a TTarget, returns the handler. - private static void SubscribeAdapter( - AvaloniaPropertyChangedEventArgs e, - Func> handler) - where TTarget : class - { - if (e.Sender is TTarget target) - { - handler(target)(e); - } - } - private class BindingAdaptor : IBinding { private IObservable _source; diff --git a/src/Avalonia.Base/AvaloniaProperty`1.cs b/src/Avalonia.Base/AvaloniaProperty`1.cs index 3937ee5658..14acc2c47f 100644 --- a/src/Avalonia.Base/AvaloniaProperty`1.cs +++ b/src/Avalonia.Base/AvaloniaProperty`1.cs @@ -30,21 +30,6 @@ namespace Avalonia _changed = new Subject>(); } - /// - /// Initializes a new instance of the class. - /// - /// The property to copy. - /// The new owner type. - /// Optional overridden metadata. - [Obsolete("Use constructor with AvaloniaProperty instead.", true)] - protected AvaloniaProperty( - AvaloniaProperty source, - Type ownerType, - AvaloniaPropertyMetadata? metadata) - : this(source as AvaloniaProperty ?? throw new InvalidOperationException(), ownerType, metadata) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs b/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs index fb70729cf8..c4684960d6 100644 --- a/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs +++ b/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs @@ -140,21 +140,6 @@ namespace Avalonia.Collections } } - [Obsolete("Causes memory leaks. Use DynamicData or similar instead.")] - public static IAvaloniaReadOnlyList CreateDerivedList( - this IAvaloniaReadOnlyList collection, - Func select) - { - var result = new AvaloniaList(); - - collection.ForEachItem( - (i, item) => result.Insert(i, select(item)), - (i, item) => result.RemoveAt(i), - () => result.Clear()); - - return result; - } - /// /// Listens for property changed events from all items in a collection. /// diff --git a/src/Avalonia.Base/DirectPropertyBase.cs b/src/Avalonia.Base/DirectPropertyBase.cs index efcb7dfecb..86e4bffaa8 100644 --- a/src/Avalonia.Base/DirectPropertyBase.cs +++ b/src/Avalonia.Base/DirectPropertyBase.cs @@ -29,21 +29,6 @@ namespace Avalonia { } - /// - /// Initializes a new instance of the class. - /// - /// The property to copy. - /// The new owner type. - /// Optional overridden metadata. - [Obsolete("Use constructor with DirectPropertyBase instead.", true)] - protected DirectPropertyBase( - AvaloniaProperty source, - Type ownerType, - AvaloniaPropertyMetadata metadata) - : this(source as DirectPropertyBase ?? throw new InvalidOperationException(), ownerType, metadata) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Avalonia.Base/EnumExtensions.cs b/src/Avalonia.Base/EnumExtensions.cs index 19eb42a700..9b74266b09 100644 --- a/src/Avalonia.Base/EnumExtensions.cs +++ b/src/Avalonia.Base/EnumExtensions.cs @@ -8,10 +8,6 @@ namespace Avalonia /// public static class EnumExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [Obsolete("This method is obsolete. Use HasAllFlags instead.")] - public static bool HasFlagCustom(this T value, T flag) where T : unmanaged, Enum - => value.HasAllFlags(flag); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool HasAllFlags(this T value, T flags) where T : unmanaged, Enum diff --git a/src/Avalonia.Base/Interactivity/RoutedEvent.cs b/src/Avalonia.Base/Interactivity/RoutedEvent.cs index a9b7dc8c89..37edb24cc1 100644 --- a/src/Avalonia.Base/Interactivity/RoutedEvent.cs +++ b/src/Avalonia.Base/Interactivity/RoutedEvent.cs @@ -113,24 +113,6 @@ namespace Avalonia.Interactivity { } - [Obsolete("Use overload taking Action.")] - public IDisposable AddClassHandler( - Func> handler, - RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, - bool handledEventsToo = false) - where TTarget : class, IInteractive - { - void Adapter(object? sender, RoutedEventArgs e) - { - if (sender is TTarget target && e is TEventArgs args) - { - handler(target)(args); - } - } - - return AddClassHandler(typeof(TTarget), Adapter, routes, handledEventsToo); - } - public IDisposable AddClassHandler( Action handler, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, diff --git a/src/Avalonia.Base/Layout/ILayoutManager.cs b/src/Avalonia.Base/Layout/ILayoutManager.cs index 143ce13a1b..88d95c81fd 100644 --- a/src/Avalonia.Base/Layout/ILayoutManager.cs +++ b/src/Avalonia.Base/Layout/ILayoutManager.cs @@ -44,17 +44,6 @@ namespace Avalonia.Layout /// void ExecuteInitialLayoutPass(); - /// - /// Executes the initial layout pass on a layout root. - /// - /// The control to lay out. - /// - /// You should not usually need to call this method explictly, the layout root will call - /// it to carry out the initial layout of the control. - /// - [Obsolete("Call ExecuteInitialLayoutPass without parameter")] - void ExecuteInitialLayoutPass(ILayoutRoot root); - /// /// Registers a control as wanting to receive effective viewport notifications. /// diff --git a/src/Avalonia.Base/Layout/LayoutManager.cs b/src/Avalonia.Base/Layout/LayoutManager.cs index b9ca6bfbd7..826947c39a 100644 --- a/src/Avalonia.Base/Layout/LayoutManager.cs +++ b/src/Avalonia.Base/Layout/LayoutManager.cs @@ -196,17 +196,6 @@ namespace Avalonia.Layout ExecuteLayoutPass(); } - [Obsolete("Call ExecuteInitialLayoutPass without parameter")] - public void ExecuteInitialLayoutPass(ILayoutRoot root) - { - if (root != _owner) - { - throw new ArgumentException("ExecuteInitialLayoutPass called with incorrect root."); - } - - ExecuteInitialLayoutPass(); - } - public void Dispose() { _disposed = true; diff --git a/src/Avalonia.Base/Layout/Layoutable.cs b/src/Avalonia.Base/Layout/Layoutable.cs index 101e867d56..527b63292d 100644 --- a/src/Avalonia.Base/Layout/Layoutable.cs +++ b/src/Avalonia.Base/Layout/Layoutable.cs @@ -460,20 +460,6 @@ namespace Avalonia.Layout _effectiveViewportChanged?.Invoke(this, e); } - /// - /// Marks a property as affecting the control's measurement. - /// - /// The properties. - /// - /// After a call to this method in a control's static constructor, any change to the - /// property will cause to be called on the element. - /// - [Obsolete("Use AffectsMeasure and specify the control type.")] - protected static void AffectsMeasure(params AvaloniaProperty[] properties) - { - AffectsMeasure(properties); - } - /// /// Marks a property as affecting the control's measurement. /// @@ -497,20 +483,6 @@ namespace Avalonia.Layout } } - /// - /// Marks a property as affecting the control's arrangement. - /// - /// The properties. - /// - /// After a call to this method in a control's static constructor, any change to the - /// property will cause to be called on the element. - /// - [Obsolete("Use AffectsArrange and specify the control type.")] - protected static void AffectsArrange(params AvaloniaProperty[] properties) - { - AffectsArrange(properties); - } - /// /// Marks a property as affecting the control's arrangement. /// diff --git a/src/Avalonia.Base/Media/Imaging/Bitmap.cs b/src/Avalonia.Base/Media/Imaging/Bitmap.cs index 5f1617d778..cf8a31c3e9 100644 --- a/src/Avalonia.Base/Media/Imaging/Bitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/Bitmap.cs @@ -89,22 +89,6 @@ namespace Avalonia.Media.Imaging PlatformImpl.Dispose(); } - /// - /// Initializes a new instance of the class. - /// - /// The pixel format. - /// The pointer to the source bytes. - /// The size of the bitmap in device pixels. - /// The DPI of the bitmap. - /// The number of bytes per row. - [Obsolete("Use overload taking an AlphaFormat.")] - public Bitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) - { - var ri = GetFactory(); - PlatformImpl = RefCountable.Create(ri - .LoadBitmap(format, ri.DefaultAlphaFormat, data, size, dpi, stride)); - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs b/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs index 1f39b1344d..1aac8efac7 100644 --- a/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs @@ -9,18 +9,6 @@ namespace Avalonia.Media.Imaging /// public class WriteableBitmap : Bitmap { - /// - /// Initializes a new instance of the class. - /// - /// The size of the bitmap in device pixels. - /// The DPI of the bitmap. - /// The pixel format (optional). - /// An . - [Obsolete("Use overload taking an AlphaFormat.")] - public WriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null) - : base(CreatePlatformImpl(size, dpi, format, null)) - { - } /// /// Initializes a new instance of the class. @@ -30,7 +18,7 @@ namespace Avalonia.Media.Imaging /// The pixel format (optional). /// The alpha format (optional). /// An . - public WriteableBitmap(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat) + public WriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null, AlphaFormat? alphaFormat = null) : base(CreatePlatformImpl(size, dpi, format, alphaFormat)) { } diff --git a/src/Avalonia.Base/Utilities/WeakObservable.cs b/src/Avalonia.Base/Utilities/WeakObservable.cs index 6bf1d4082f..e1c350d539 100644 --- a/src/Avalonia.Base/Utilities/WeakObservable.cs +++ b/src/Avalonia.Base/Utilities/WeakObservable.cs @@ -9,31 +9,6 @@ namespace Avalonia.Utilities /// public static class WeakObservable { - /// - /// Converts a .NET event conforming to the standard .NET event pattern into an observable - /// sequence, subscribing weakly. - /// - /// The type of target. - /// The type of the event args. - /// Object instance that exposes the event to convert. - /// Name of the event to convert. - /// - [Obsolete("Use WeakEvent-based overload")] - public static IObservable> FromEventPattern( - TTarget target, - string eventName) - where TEventArgs : EventArgs - { - _ = target ?? throw new ArgumentNullException(nameof(target)); - _ = eventName ?? throw new ArgumentNullException(nameof(eventName)); - - return Observable.Create>(observer => - { - var handler = new Handler(observer); - WeakSubscriptionManager.Subscribe(target, eventName, handler); - return () => WeakSubscriptionManager.Unsubscribe(target, eventName, handler); - }).Publish().RefCount(); - } private class Handler : IWeakSubscriber, diff --git a/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs b/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs deleted file mode 100644 index dc9e86cc32..0000000000 --- a/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; - -namespace Avalonia.Utilities -{ - /// - /// Manages subscriptions to events using weak listeners. - /// - public static class WeakSubscriptionManager - { - /// - /// Subscribes to an event on an object using a weak subscription. - /// - /// The type of the target. - /// The type of the event arguments. - /// The event source. - /// The name of the event. - /// The subscriber. - [Obsolete("Use WeakEvent")] - public static void Subscribe(TTarget target, string eventName, IWeakSubscriber subscriber) - where TEventArgs : EventArgs - { - _ = target ?? throw new ArgumentNullException(nameof(target)); - - var dic = SubscriptionTypeStorage.Subscribers.GetOrCreateValue(target); - - if (!dic.TryGetValue(eventName, out var sub)) - { - dic[eventName] = sub = new Subscription(dic, typeof(TTarget), target, eventName); - } - - sub.Add(new WeakReference>(subscriber)); - } - - /// - /// Unsubscribes from an event. - /// - /// The type of the event arguments. - /// The event source. - /// The name of the event. - /// The subscriber. - public static void Unsubscribe(object target, string eventName, IWeakSubscriber subscriber) - where T : EventArgs - { - if (SubscriptionTypeStorage.Subscribers.TryGetValue(target, out var dic)) - { - if (dic.TryGetValue(eventName, out var sub)) - { - sub.Remove(subscriber); - } - } - } - - private static class SubscriptionTypeStorage - where T : EventArgs - { - public static readonly ConditionalWeakTable> Subscribers - = new ConditionalWeakTable>(); - } - - private class SubscriptionDic : Dictionary> - where T : EventArgs - { - } - - private static readonly Dictionary> Accessors - = new Dictionary>(); - - private class Subscription where T : EventArgs - { - private readonly EventInfo _info; - private readonly SubscriptionDic _sdic; - private readonly object _target; - private readonly string _eventName; - private readonly Delegate _delegate; - - private WeakReference>?[] _data = new WeakReference>?[16]; - private int _count = 0; - - public Subscription(SubscriptionDic sdic, Type targetType, object target, string eventName) - { - _sdic = sdic; - _target = target; - _eventName = eventName; - if (!Accessors.TryGetValue(targetType, out var evDic)) - Accessors[targetType] = evDic = new Dictionary(); - - if (evDic.TryGetValue(eventName, out var info)) - { - _info = info; - } - else - { - var ev = targetType.GetRuntimeEvents().FirstOrDefault(x => x.Name == eventName); - - if (ev == null) - { - throw new ArgumentException( - $"The event {eventName} was not found on {target.GetType()}."); - } - - evDic[eventName] = _info = ev; - } - - var del = new Action(OnEvent); - _delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType!, del.Target); - _info.AddMethod!.Invoke(target, new[] { _delegate }); - } - - void Destroy() - { - _info.RemoveMethod!.Invoke(_target, new[] { _delegate }); - _sdic.Remove(_eventName); - } - - public void Add(WeakReference> s) - { - if (_count == _data.Length) - { - //Extend capacity - var ndata = new WeakReference>?[_data.Length*2]; - Array.Copy(_data, ndata, _data.Length); - _data = ndata; - } - _data[_count] = s!; - _count++; - } - - public void Remove(IWeakSubscriber s) - { - var removed = false; - - for (int c = 0; c < _count; ++c) - { - var reference = _data[c]; - IWeakSubscriber? instance; - - if (reference != null && reference.TryGetTarget(out instance) && instance == s) - { - _data[c] = null; - removed = true; - } - } - - if (removed) - { - Compact(); - } - } - - void Compact() - { - int empty = -1; - for (int c = 0; c < _count; c++) - { - var r = _data[c]; - //Mark current index as first empty - if (r == null && empty == -1) - empty = c; - //If current element isn't null and we have an empty one - if (r != null && empty != -1) - { - _data[c] = null; - _data[empty] = r; - empty++; - } - } - if (empty != -1) - _count = empty; - if (_count == 0) - Destroy(); - } - - void OnEvent(object sender, T eventArgs) - { - var needCompact = false; - for(var c=0; c<_count; c++) - { - var r = _data[c]; - if (r?.TryGetTarget(out var sub) == true) - sub!.OnEvent(sender, eventArgs); - else - needCompact = true; - } - if (needCompact) - Compact(); - } - } - } -} diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index 8feba116f0..69389def56 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -338,22 +338,6 @@ namespace Avalonia Contract.Requires(context != null); } - /// - /// Indicates that a property change should cause to be - /// called. - /// - /// The properties. - /// - /// This method should be called in a control's static constructor with each property - /// on the control which when changed should cause a redraw. This is similar to WPF's - /// FrameworkPropertyMetadata.AffectsRender flag. - /// - [Obsolete("Use AffectsRender and specify the control type.")] - protected static void AffectsRender(params AvaloniaProperty[] properties) - { - AffectsRender(properties); - } - /// /// Indicates that a property change should cause to be /// called. diff --git a/src/Avalonia.Base/VisualTree/IVisualTreeHost.cs b/src/Avalonia.Base/VisualTree/IVisualTreeHost.cs deleted file mode 100644 index e47377063f..0000000000 --- a/src/Avalonia.Base/VisualTree/IVisualTreeHost.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Avalonia.VisualTree -{ - /// - /// Interface for controls that host their own separate visual tree, such as popups. - /// - [Obsolete] - public interface IVisualTreeHost - { - /// - /// Gets the root of the hosted visual tree. - /// - /// - /// The root of the hosted visual tree. - /// - IVisual? Root { get; } - } -} diff --git a/src/Avalonia.Controls/Primitives/Popup.cs b/src/Avalonia.Controls/Primitives/Popup.cs index 3573ad9aaa..468b743d9e 100644 --- a/src/Avalonia.Controls/Primitives/Popup.cs +++ b/src/Avalonia.Controls/Primitives/Popup.cs @@ -22,9 +22,7 @@ namespace Avalonia.Controls.Primitives /// /// Displays a popup window. /// -#pragma warning disable CS0612 // Type or member is obsolete - public class Popup : Control, IVisualTreeHost, IPopupHostProvider -#pragma warning restore CS0612 // Type or member is obsolete + public class Popup : Control, IPopupHostProvider { public static readonly StyledProperty WindowManagerAddShadowHintProperty = AvaloniaProperty.Register(nameof(WindowManagerAddShadowHint), false); @@ -372,11 +370,6 @@ namespace Avalonia.Controls.Primitives set { SetValue(TopmostProperty, value); } } - /// - /// Gets the root of the popup window. - /// - IVisual? IVisualTreeHost.Root => _openState?.PopupHost.HostedVisualTreeRoot; - IPopupHost? IPopupHostProvider.PopupHost => Host; event Action? IPopupHostProvider.PopupHostChanged diff --git a/src/Avalonia.Controls/Remote/RemoteWidget.cs b/src/Avalonia.Controls/Remote/RemoteWidget.cs index a88e0fd3d8..27578ddc78 100644 --- a/src/Avalonia.Controls/Remote/RemoteWidget.cs +++ b/src/Avalonia.Controls/Remote/RemoteWidget.cs @@ -77,10 +77,8 @@ namespace Avalonia.Controls.Remote _bitmap.PixelSize.Height != _lastFrame.Height) { _bitmap?.Dispose(); -#pragma warning disable CS0618 // Type or member is obsolete _bitmap = new WriteableBitmap(new PixelSize(_lastFrame.Width, _lastFrame.Height), new Vector(96, 96), fmt); -#pragma warning restore CS0618 // Type or member is obsolete } using (var l = _bitmap.Lock()) { diff --git a/src/Avalonia.X11/X11IconLoader.cs b/src/Avalonia.X11/X11IconLoader.cs index 0357fdd94e..ffac3c55e2 100644 --- a/src/Avalonia.X11/X11IconLoader.cs +++ b/src/Avalonia.X11/X11IconLoader.cs @@ -68,9 +68,7 @@ namespace Avalonia.X11 public void Save(Stream outputStream) { using (var wr = -#pragma warning disable CS0618 // Type or member is obsolete new WriteableBitmap(new PixelSize(_width, _height), new Vector(96, 96), PixelFormat.Bgra8888)) -#pragma warning restore CS0618 // Type or member is obsolete { using (var fb = wr.Lock()) { diff --git a/tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs b/tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs deleted file mode 100644 index b1b2d3d8f2..0000000000 --- a/tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System.Linq; -using Avalonia.Collections; -using Xunit; - -namespace Avalonia.Base.UnitTests.Collections -{ - public class AvaloniaListExtenionsTests - { -#pragma warning disable CS0618 // Type or member is obsolete - [Fact] - public void CreateDerivedList_Creates_Initial_Items() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - - var target = source.CreateDerivedList(x => new Wrapper(x)); - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Add() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.Add(4); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Insert() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.Insert(1, 4); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Remove() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.Remove(2); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_RemoveRange() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.RemoveRange(1, 2); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Move() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.Move(2, 0); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Theory] - [InlineData(0, 2, 3)] - [InlineData(0, 2, 4)] - [InlineData(0, 2, 5)] - [InlineData(0, 4, 4)] - [InlineData(1, 2, 0)] - [InlineData(1, 2, 4)] - [InlineData(1, 2, 5)] - [InlineData(1, 4, 0)] - [InlineData(2, 2, 0)] - [InlineData(2, 2, 1)] - [InlineData(2, 2, 3)] - [InlineData(2, 2, 4)] - [InlineData(2, 2, 5)] - [InlineData(4, 2, 0)] - [InlineData(4, 2, 1)] - [InlineData(4, 2, 3)] - [InlineData(5, 1, 0)] - [InlineData(5, 1, 3)] - public void CreateDerivedList_Handles_MoveRange(int oldIndex, int count, int newIndex) - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3, 4, 5 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.MoveRange(oldIndex, count, newIndex); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Replace() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source[1] = 4; - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } - - [Fact] - public void CreateDerivedList_Handles_Clear() - { - var source = new AvaloniaList(new[] { 0, 1, 2, 3 }); - var target = source.CreateDerivedList(x => new Wrapper(x)); - - source.Clear(); - - var result = target.Select(x => x.Value).ToList(); - - Assert.Equal(source, result); - } -#pragma warning restore CS0618 // Type or member is obsolete - - - private class Wrapper - { - public Wrapper(int value) - { - Value = value; - } - - public int Value { get; } - } - } -} diff --git a/tests/Avalonia.Base.UnitTests/WeakSubscriptionManagerTests.cs b/tests/Avalonia.Base.UnitTests/WeakSubscriptionManagerTests.cs deleted file mode 100644 index 7b2cac2819..0000000000 --- a/tests/Avalonia.Base.UnitTests/WeakSubscriptionManagerTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Avalonia.Utilities; -using Xunit; - -namespace Avalonia.Base.UnitTests -{ - public class WeakSubscriptionManagerTests - { - class EventSource - { - public event EventHandler Event; - - public void Fire() - { - Event?.Invoke(this, new EventArgs()); - } - } - - class Subscriber : IWeakSubscriber - { - private readonly Action _onEvent; - - public Subscriber(Action onEvent) - { - _onEvent = onEvent; - } - - public void OnEvent(object sender, EventArgs ev) - { - _onEvent?.Invoke(); - } - } - - [Fact] - public void EventShoudBePassedToSubscriber() - { - bool handled = false; - var subscriber = new Subscriber(() => handled = true); - var source = new EventSource(); - WeakSubscriptionManager.Subscribe(source, "Event", subscriber); - source.Fire(); - Assert.True(handled); - } - - - [Fact] - public void EventHandlerShouldNotBeKeptAlive() - { - bool handled = false; - var source = new EventSource(); - AddSubscriber(source, "Event", () => handled = true); - for (int c = 0; c < 10; c++) - { - GC.Collect(); - GC.Collect(3, GCCollectionMode.Forced, true); - } - source.Fire(); - Assert.False(handled); - } - - private void AddSubscriber(EventSource source, string name, Action func) - { - WeakSubscriptionManager.Subscribe(source, name, new Subscriber(func)); - } - } -} diff --git a/tests/Avalonia.RenderTests/Media/BitmapTests.cs b/tests/Avalonia.RenderTests/Media/BitmapTests.cs index b629304b77..d52539c371 100644 --- a/tests/Avalonia.RenderTests/Media/BitmapTests.cs +++ b/tests/Avalonia.RenderTests/Media/BitmapTests.cs @@ -102,9 +102,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media [InlineData(PixelFormat.Bgra8888), InlineData(PixelFormat.Rgba8888)] public void WriteableBitmapShouldBeUsable(PixelFormat fmt) { -#pragma warning disable CS0618 // Type or member is obsolete var writeableBitmap = new WriteableBitmap(new PixelSize(256, 256), new Vector(96, 96), fmt); -#pragma warning restore CS0618 // Type or member is obsolete var data = new int[256 * 256]; for (int y = 0; y < 256; y++)