< Summary

Information
Class: MyNet.UI.ViewModels.List.Factories.ListViewModelFactory
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/Factories/ListViewModelFactory.cs
Tag: 323_28699572109
Line coverage
80%
Covered lines: 21
Uncovered lines: 5
Coverable lines: 26
Total lines: 173
Line coverage: 80.7%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Create(...)100%210%
CreateCrud(...)100%11100%
Create(...)100%210%
CreateCrud(...)50%22100%
CreateVirtualized(...)100%11100%
CreateVirtualized(...)50%22100%
CreateSelection(...)100%22100%
CreateSelection(...)100%11100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ListViewModelFactory.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 MyNet.Observable.Collections;
 10using MyNet.Observable.Collections.Selection;
 11using MyNet.Observable.Collections.Sources;
 12using MyNet.UI.ViewModels.List.Selection;
 13using MyNet.UI.ViewModels.List.Services;
 14
 15namespace MyNet.UI.ViewModels.List.Factories;
 16
 17/// <summary>
 18/// Provides simple factory methods to create list view models with optional shared configuration.
 19/// </summary>
 20public static class ListViewModelFactory
 21{
 22    /// <summary>
 23    /// Creates a new instance of <see cref="ListViewModel{T}"/> with the specified data provider and optional configura
 24    /// </summary>
 25    /// <param name="provider">The data provider for the list view model.</param>
 26    /// <param name="options">Optional configuration for the list view model.</param>
 27    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 28    /// <returns>A new instance of <see cref="ListViewModel{T}"/>.</returns>
 29    public static ListViewModel<T> Create<T>(IListDataProvider<T> provider, ListViewModelOptions<T>? options = null)
 30        where T : notnull
 31    {
 032        ArgumentNullException.ThrowIfNull(provider);
 33
 034        return new(provider, options);
 35    }
 36
 37    /// <summary>
 38    /// Creates a new instance of <see cref="CrudListViewModel{T}"/> with the specified data provider, CRUD service and 
 39    /// </summary>
 40    /// <param name="provider">The data provider for the list view model.</param>
 41    /// <param name="crudService">The CRUD service used by the view model commands.</param>
 42    /// <param name="options">Optional configuration for the list view model.</param>
 43    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 44    /// <returns>A new instance of <see cref="CrudListViewModel{T}"/>.</returns>
 45    public static CrudListViewModel<T> CreateCrud<T>(
 46        IListDataProvider<T> provider,
 47        ICrudService<T> crudService,
 48        ListViewModelOptions<T>? options = null)
 49        where T : notnull
 50    {
 951        ArgumentNullException.ThrowIfNull(provider);
 652        ArgumentNullException.ThrowIfNull(crudService);
 53
 354        return new(provider, crudService, options);
 55    }
 56
 57    /// <summary>
 58    /// Creates a new instance of <see cref="ListViewModel{T}"/> with the specified items and optional configuration.
 59    /// </summary>
 60    /// <param name="items">The items to be displayed in the list view model.</param>
 61    /// <param name="options">Optional configuration for the list view model.</param>
 62    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 63    /// <returns>A new instance of <see cref="ListViewModel{T}"/>.</returns>
 64    public static ListViewModel<T> Create<T>(
 65        IEnumerable<T> items,
 66        ListViewModelOptions<T>? options = null)
 67        where T : notnull
 68    {
 069        ArgumentNullException.ThrowIfNull(items);
 70
 071        var source = SourceEngine<T>.From(items, readOnly: false);
 072        return new(source, options);
 73    }
 74
 75    /// <summary>
 76    /// Creates a new instance of <see cref="CrudListViewModel{T}"/> with the specified items, CRUD service and optional
 77    /// </summary>
 78    /// <param name="items">The items to be displayed in the list view model.</param>
 79    /// <param name="crudService">The CRUD service used by the view model commands.</param>
 80    /// <param name="options">Optional configuration for the list view model.</param>
 81    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 82    /// <returns>A new instance of <see cref="CrudListViewModel{T}"/>.</returns>
 83    public static CrudListViewModel<T> CreateCrud<T>(
 84        IEnumerable<T> items,
 85        ICrudService<T> crudService,
 86        ListViewModelOptions<T>? options = null)
 87        where T : notnull
 88    {
 689        ArgumentNullException.ThrowIfNull(items);
 390        ArgumentNullException.ThrowIfNull(crudService);
 91
 392        var source = SourceEngine<T>.From(items, readOnly: false);
 393        var provider = new ExtendedCollectionDataProvider<T>(new(source, options?.Scheduler));
 94
 395        return new(provider, crudService, options);
 96    }
 97
 98    /// <summary>
 99    /// Creates a new instance of <see cref="VirtualizedListViewModel{T}"/> with the specified data provider and optiona
 100    /// </summary>
 101    /// <param name="provider">The data provider for the list view model.</param>
 102    /// <param name="options">Optional configuration for the list view model.</param>
 103    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 104    /// <returns>A new instance of <see cref="VirtualizedListViewModel{T}"/>.</returns>
 105    public static VirtualizedListViewModel<T> CreateVirtualized<T>(
 106        IListDataProvider<T> provider,
 107        ListViewModelOptions<T>? options = null)
 108        where T : notnull
 109    {
 6110        ArgumentNullException.ThrowIfNull(provider);
 111
 3112        return new(provider, options);
 113    }
 114
 115    /// <summary>
 116    /// Creates a new instance of <see cref="VirtualizedListViewModel{T}"/> with the specified items and optional config
 117    /// </summary>
 118    /// <param name="items">The items to be displayed in the list view model.</param>
 119    /// <param name="options">Optional configuration for the list view model.</param>
 120    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 121    /// <returns>A new instance of <see cref="VirtualizedListViewModel{T}"/>.</returns>
 122    public static VirtualizedListViewModel<T> CreateVirtualized<T>(
 123        IEnumerable<T> items,
 124        ListViewModelOptions<T>? options = null)
 125        where T : notnull
 126    {
 6127        ArgumentNullException.ThrowIfNull(items);
 128
 3129        var source = SourceEngine<T>.From(items, readOnly: false);
 3130        var provider = new ExtendedCollectionDataProvider<T>(new(source, options?.Scheduler));
 131
 3132        return new(provider, options);
 133    }
 134
 135    /// <summary>
 136    /// Creates a new instance of <see cref="SelectableListViewModel{T}"/> with the specified items and optional configu
 137    /// </summary>
 138    /// <param name="items">The items to be displayed in the list view model.</param>
 139    /// <param name="options">Optional configuration for the list view model.</param>
 140    /// <param name="selectionMode">The selection mode for the list view model.</param>
 141    /// <typeparam name="T">The type of items in the list view model.</typeparam>
 142    /// <returns>A new instance of <see cref="SelectableListViewModel{T}"/>.</returns>
 143    public static SelectableListViewModel<T> CreateSelection<T>(
 144        IEnumerable<T> items,
 145        ListViewModelOptions<T>? options = null,
 146        SelectionMode selectionMode = SelectionMode.Multiple)
 147        where T : notnull
 148    {
 18149        ArgumentNullException.ThrowIfNull(items);
 150
 18151        options ??= new();
 152
 18153        var source = SourceEngine<T>.From(items, readOnly: false);
 18154        var collection = new ExtendedCollection<T>(source, options.Scheduler);
 155
 18156        return new(collection, selectionMode, options);
 157    }
 158
 159    /// <summary>
 160    /// Creates a selectable list view model from an existing extended collection.
 161    /// </summary>
 162    public static SelectableListViewModel<T> CreateSelection<T>(
 163        ExtendedCollection<T> collection,
 164        ListViewModelOptions<T>? options = null,
 165        SelectionMode selectionMode = SelectionMode.Multiple)
 166        where T : notnull
 167    {
 3168        ArgumentNullException.ThrowIfNull(collection);
 169
 3170        return new(collection, selectionMode, options);
 171    }
 172}
 173