// This source file is adapted from the WinUI project.
// (https://github.com/microsoft/microsoft-ui-xaml)
//
// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Controls.Utils;
#nullable enable
namespace Avalonia.Controls
{
///
/// Represents a standardized view of the supported interactions between a given
/// or and its items.
///
public class ItemsSourceView : INotifyCollectionChanged, IDisposable, IReadOnlyList
{
///
/// Gets an empty
///
public static ItemsSourceView Empty { get; } = new ItemsSourceView(Array.Empty());
private readonly IList _inner;
private INotifyCollectionChanged? _notifyCollectionChanged;
///
/// Initializes a new instance of the ItemsSourceView class for the specified data source.
///
/// The data source.
public ItemsSourceView(IEnumerable source)
: this((IEnumerable)source)
{
}
private protected ItemsSourceView(IEnumerable source)
{
source = source ?? throw new ArgumentNullException(nameof(source));
if (source is IList list)
{
_inner = list;
}
else if (source is IEnumerable