using System; using System.Collections; using System.Collections.Generic; using Avalonia.Controls.Selection; #nullable enable namespace Avalonia.Controls.Selection { public abstract class SelectionModelSelectionChangedEventArgs : EventArgs { /// /// Gets the indexes of the items that were removed from the selection. /// public abstract IReadOnlyList DeselectedIndexes { get; } /// /// Gets the indexes of the items that were added to the selection. /// public abstract IReadOnlyList SelectedIndexes { get; } /// /// Gets the items that were removed from the selection. /// public IReadOnlyList DeselectedItems => GetUntypedDeselectedItems(); /// /// Gets the items that were added to the selection. /// public IReadOnlyList SelectedItems => GetUntypedSelectedItems(); protected abstract IReadOnlyList GetUntypedDeselectedItems(); protected abstract IReadOnlyList GetUntypedSelectedItems(); } public class SelectionModelSelectionChangedEventArgs : SelectionModelSelectionChangedEventArgs { private IReadOnlyList? _deselectedItems; private IReadOnlyList? _selectedItems; public SelectionModelSelectionChangedEventArgs( IReadOnlyList? deselectedIndices = null, IReadOnlyList? selectedIndices = null, IReadOnlyList? deselectedItems = null, IReadOnlyList? selectedItems = null) { DeselectedIndexes = deselectedIndices ?? Array.Empty(); SelectedIndexes = selectedIndices ?? Array.Empty(); DeselectedItems = deselectedItems ?? Array.Empty(); SelectedItems = selectedItems ?? Array.Empty(); } /// /// Gets the indexes of the items that were removed from the selection. /// public override IReadOnlyList DeselectedIndexes { get; } /// /// Gets the indexes of the items that were added to the selection. /// public override IReadOnlyList SelectedIndexes { get; } /// /// Gets the items that were removed from the selection. /// public new IReadOnlyList DeselectedItems { get; } /// /// Gets the items that were added to the selection. /// public new IReadOnlyList SelectedItems { get; } protected override IReadOnlyList GetUntypedDeselectedItems() { return _deselectedItems ??= (DeselectedItems as IReadOnlyList) ?? new SelectedItems.Untyped(DeselectedItems); } protected override IReadOnlyList GetUntypedSelectedItems() { return _selectedItems ??= (SelectedItems as IReadOnlyList) ?? new SelectedItems.Untyped(SelectedItems); } } }