< Summary

Information
Class: MyNet.UI.ViewModels.List.VirtualizedListViewModel<T>
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/VirtualizedListViewModel.cs
Tag: 323_28699572109
Line coverage
92%
Covered lines: 25
Uncovered lines: 2
Coverable lines: 27
Total lines: 86
Line coverage: 92.5%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
set_VisibleStartIndex(...)100%22100%
set_VisibleCount(...)50%2275%
get_VisibleItems()50%2290%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/VirtualizedListViewModel.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="VirtualizedListViewModel.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Collections.Specialized;
 10using System.Linq;
 11using MyNet.UI.ViewModels.List.Factories;
 12
 13namespace MyNet.UI.ViewModels.List;
 14
 15/// <summary>
 16/// Provides a list view model exposing a virtualized visible window over list items.
 17/// </summary>
 18/// <typeparam name="T">The item type.</typeparam>
 19public class VirtualizedListViewModel<T> : ListViewModel<T>, IVirtualizedListViewModel<T>
 20    where T : notnull
 21{
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="VirtualizedListViewModel{T}"/> class.
 24    /// </summary>
 25    public VirtualizedListViewModel(IListDataProvider<T> dataProvider, ListViewModelOptions<T>? options = null)
 1526        : base(dataProvider, options)
 27    {
 1528        if (Items is INotifyCollectionChanged itemsNotify)
 29        {
 1530            Disposables.Add(
 1531                System.Reactive.Linq.Observable.FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionCh
 1532                        h => itemsNotify.CollectionChanged += h,
 1533                        h => itemsNotify.CollectionChanged -= h)
 1534                    .Subscribe(_ => NotifyPropertyChanged(nameof(VisibleItems))));
 35        }
 1536    }
 37
 38    /// <inheritdoc />
 39    public int VisibleStartIndex
 40    {
 41        get;
 42        set
 43        {
 944            if (!SetProperty(ref field, Math.Max(0, value)))
 345                return;
 46
 647            NotifyPropertyChanged(nameof(VisibleItems));
 648        }
 49    }
 50
 51    /// <inheritdoc />
 52    public int VisibleCount
 53    {
 54        get;
 55        set
 56        {
 957            if (!SetProperty(ref field, Math.Max(1, value)))
 058                return;
 59
 960            NotifyPropertyChanged(nameof(VisibleItems));
 961        }
 62    }
 63
 1564        = 50;
 65
 66    /// <inheritdoc />
 67    public IReadOnlyList<T> VisibleItems
 68    {
 69        get
 70        {
 971            if (Items.Count == 0)
 072                return [];
 73
 974            var start = Math.Min(VisibleStartIndex, Items.Count - 1);
 975            var count = Math.Min(VisibleCount, Items.Count - start);
 76
 977            return
 978            [
 979                .. Items
 980                    .Skip(start)
 981                    .Take(count)
 982            ];
 83        }
 84    }
 85}
 86