// 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;
namespace Avalonia.Controls
{
///
/// Represents a standardized view of the supported interactions between a given ItemsSource
/// object and an control.
///
///
/// Components written to work with ItemsRepeater should consume the
/// via ItemsSourceView since this provides a normalized
/// view of the Items. That way, each component does not need to know if the source is an
/// IEnumerable, an IList, or something else.
///
public class ItemsSourceView : INotifyCollectionChanged, IDisposable
{
private readonly IList _inner;
private INotifyCollectionChanged _notifyCollectionChanged;
private int _cachedSize = -1;
///
/// Initializes a new instance of the ItemsSourceView class for the specified data source.
///
/// The data source.
public ItemsSourceView(IEnumerable source)
{
Contract.Requires(source != null);
if (source is IList list)
{
_inner = list;
}
else if (source is IEnumerable