< Summary

Information
Class: MyNet.Observable.Collections.Sorting.SortingBuilder<T>
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Sorting/SortingBuilder.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 68
Line coverage: 100%
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
.ctor()100%11100%
Create()100%11100%
Add(...)100%11100%
ThenBy(...)100%11100%
ThenByDescending(...)100%11100%
Build()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Sorting/SortingBuilder.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="SortingBuilder.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.ComponentModel;
 10using System.Linq.Expressions;
 11
 12namespace MyNet.Observable.Collections.Sorting;
 13
 14/// <summary>
 15/// Provides a builder for constructing a list of sorting properties for type T, allowing to define multiple sorting lev
 16/// </summary>
 17/// <typeparam name="T">The type of the elements to be sorted.</typeparam>
 18public class SortingBuilder<T>
 19{
 1820    private readonly List<ISortingProperty<T>> _properties = [];
 21
 22    /// <summary>
 23    /// Creates a new instance of the <see cref="SortingBuilder{T}"/> class, providing a fluent API for constructing a l
 24    /// </summary>
 25    /// <returns>A new instance of the <see cref="SortingBuilder{T}"/> class.</returns>
 1826    public static SortingBuilder<T> Create() => new();
 27
 28    /// <summary>
 29    /// Adds a sorting property to the builder with the specified expression and sort direction.
 30    /// </summary>
 31    /// <param name="expression">The expression used to select the property to sort by.</param>
 32    /// <param name="direction">The direction in which to sort the property.</param>
 33    /// <returns>The current instance of the <see cref="SortingBuilder{T}"/> for method chaining.</returns>
 34    public SortingBuilder<T> Add(Expression<Func<T, object?>> expression, ListSortDirection direction)
 35    {
 1836        _properties.Add(new ExpressionSortingProperty<T>(expression, direction));
 1837        return this;
 38    }
 39
 40    /// <summary>
 41    /// Adds a sorting property to the builder with the specified expression and ascending sort direction. This method i
 42    /// </summary>
 43    /// <param name="expression">The expression used to select the property to sort by.</param>
 44    /// <returns>The current instance of the <see cref="SortingBuilder{T}"/> for method chaining.</returns>
 45    public SortingBuilder<T> ThenBy(Expression<Func<T, object?>> expression)
 46    {
 1247        Add(expression, ListSortDirection.Ascending);
 1248        return this;
 49    }
 50
 51    /// <summary>
 52    /// Adds a sorting property to the builder with the specified expression and descending sort direction. This method 
 53    /// </summary>
 54    /// <param name="expression">The expression used to select the property to sort by.</param>
 55    /// <returns>The current instance of the <see cref="SortingBuilder{T}"/> for method chaining.</returns>
 56    public SortingBuilder<T> ThenByDescending(Expression<Func<T, object?>> expression)
 57    {
 358        Add(expression, ListSortDirection.Descending);
 359        return this;
 60    }
 61
 62    /// <summary>
 63    /// Builds the list of sorting properties that have been added to the builder. This method returns a read-only list 
 64    /// </summary>
 65    /// <returns>A read-only list of <see cref="ISortingProperty{T}"/> instances representing the sorting configuration.
 1866    public IReadOnlyList<ISortingProperty<T>> Build() => _properties;
 67}
 68