< Summary

Information
Class: MyNet.UI.Dialogs.DialogServiceListExtensions
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/Extensions/DialogServiceListExtensions.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 107
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateList(...)100%210%
CreateList(...)100%210%
CreateSelection(...)100%210%
CreateSelection(...)100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/Extensions/DialogServiceListExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DialogServiceListExtensions.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.Selection;
 10using MyNet.UI.Commands;
 11using MyNet.UI.Dialogs.ContentDialogs;
 12using MyNet.UI.ViewModels.Dialog;
 13using MyNet.UI.ViewModels.List;
 14using MyNet.UI.ViewModels.List.Factories;
 15using MyNet.UI.ViewModels.List.Selection;
 16
 17#pragma warning disable IDE0130
 18namespace MyNet.UI.Dialogs;
 19#pragma warning restore IDE0130
 20
 21/// <summary>
 22/// Provides fluent helpers to create list-based dialogs from existing list view models or raw item sequences.
 23/// </summary>
 24public static class DialogServiceListExtensions
 25{
 26    extension(IDialogService dialogService)
 27    {
 28        /// <summary>
 29        /// Creates a fluent builder for a list dialog backed by an existing list view model.
 30        /// </summary>
 31        /// <typeparam name="T">The item type.</typeparam>
 32        /// <typeparam name="TList">The concrete list view model type.</typeparam>
 33        /// <param name="list">The list view model displayed by the dialog.</param>
 34        /// <param name="commandFactory">Optional command factory used by the dialog view model.</param>
 35        /// <returns>A typed fluent builder for the dialog.</returns>
 36        public IDialogBuilder<IReadOnlyCollection<T>> CreateList<T, TList>(TList list, ICommandFactory? commandFactory =
 37            where T : notnull
 38            where TList : IListViewModel<T>
 39        {
 040            ArgumentNullException.ThrowIfNull(dialogService);
 041            ArgumentNullException.ThrowIfNull(list);
 42
 043            return dialogService.Create(new ListDialogViewModel<T, TList>(list, commandFactory: commandFactory));
 44        }
 45
 46        /// <summary>
 47        /// Creates a fluent builder for a list dialog from a raw sequence of items.
 48        /// </summary>
 49        /// <typeparam name="T">The item type.</typeparam>
 50        /// <param name="items">The items to display.</param>
 51        /// <param name="listOptions">Optional configuration for the created list view model.</param>
 52        /// <param name="commandFactory">Optional command factory used by the dialog view model.</param>
 53        /// <returns>A typed fluent builder for the dialog.</returns>
 54        public IDialogBuilder<IReadOnlyCollection<T>> CreateList<T>(
 55            IEnumerable<T> items,
 56            ListViewModelOptions<T>? listOptions = null,
 57            ICommandFactory? commandFactory = null)
 58            where T : notnull
 59        {
 060            ArgumentNullException.ThrowIfNull(dialogService);
 061            ArgumentNullException.ThrowIfNull(items);
 62
 063            var list = ListViewModelFactory.Create(items, listOptions);
 064            return dialogService.Create(new ListDialogViewModel<T, ListViewModel<T>>(list, commandFactory: commandFactor
 65        }
 66
 67        /// <summary>
 68        /// Creates a fluent builder for a selection dialog backed by an existing selectable list view model.
 69        /// </summary>
 70        /// <typeparam name="T">The item type.</typeparam>
 71        /// <param name="list">The selectable list view model displayed by the dialog.</param>
 72        /// <param name="commandFactory">Optional command factory used by the dialog view model.</param>
 73        /// <returns>A typed fluent builder for the dialog.</returns>
 74        public IDialogBuilder<IReadOnlyCollection<T>> CreateSelection<T>(SelectableListViewModel<T> list, ICommandFactor
 75            where T : notnull
 76        {
 077            ArgumentNullException.ThrowIfNull(dialogService);
 078            ArgumentNullException.ThrowIfNull(list);
 79
 080            return dialogService.Create(new SelectionDialogViewModel<T>(list, commandFactory: commandFactory));
 81        }
 82
 83        /// <summary>
 84        /// Creates a fluent builder for a selection dialog from a raw sequence of items.
 85        /// </summary>
 86        /// <typeparam name="T">The item type.</typeparam>
 87        /// <param name="items">The items to display.</param>
 88        /// <param name="selectionMode">The selection mode used by the generated list view model.</param>
 89        /// <param name="listOptions">Optional configuration for the created list view model.</param>
 90        /// <param name="commandFactory">Optional command factory used by the dialog view model.</param>
 91        /// <returns>A typed fluent builder for the dialog.</returns>
 92        public IDialogBuilder<IReadOnlyCollection<T>> CreateSelection<T>(
 93            IEnumerable<T> items,
 94            SelectionMode selectionMode = SelectionMode.Multiple,
 95            ListViewModelOptions<T>? listOptions = null,
 96            ICommandFactory? commandFactory = null)
 97            where T : notnull
 98        {
 099            ArgumentNullException.ThrowIfNull(dialogService);
 0100            ArgumentNullException.ThrowIfNull(items);
 101
 0102            var list = ListViewModelFactory.CreateSelection(items, listOptions, selectionMode);
 0103            return dialogService.Create(new SelectionDialogViewModel<T>(list, commandFactory: commandFactory));
 104        }
 105    }
 106}
 107