< Summary

Information
Class: MyNet.Observable.Collections.Grouping.GroupingBuilder<T>
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Grouping/GroupingBuilder.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 55
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%
Build()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Grouping/GroupingBuilder.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GroupingBuilder.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.Linq.Expressions;
 10
 11namespace MyNet.Observable.Collections.Grouping;
 12
 13/// <summary>
 14/// Provides a builder for constructing a list of grouping properties for type T, allowing to define multiple grouping l
 15/// </summary>
 16/// <typeparam name="T">The type of the elements to be grouped.</typeparam>
 17public class GroupingBuilder<T>
 18{
 1219    private readonly List<IGroupingProperty<T>> _properties = [];
 20
 21    /// <summary>
 22    /// Creates a new instance of the <see cref="GroupingBuilder{T}"/> class, providing a fluent API for constructing a 
 23    /// </summary>
 24    /// <returns>A new instance of the <see cref="GroupingBuilder{T}"/> class.</returns>
 1225    public static GroupingBuilder<T> Create() => new();
 26
 27    /// <summary>
 28    /// Adds a grouping property to the builder with the specified expression.
 29    /// </summary>
 30    /// <param name="expression">The expression used to select the property to group by.</param>
 31    /// <returns>The current instance of the <see cref="GroupingBuilder{T}"/> for method chaining.</returns>
 32    public GroupingBuilder<T> Add(Expression<Func<T, object?>> expression)
 33    {
 634        _properties.Add(new ExpressionGroupingProperty<T>(expression));
 635        return this;
 36    }
 37
 38    /// <summary>
 39    /// Adds a grouping property to the builder with the specified expression. This method is a convenience method for a
 40    /// </summary>
 41    /// <param name="expression">The expression used to select the property to group by.</param>
 42    /// <returns>The current instance of the <see cref="GroupingBuilder{T}"/> for method chaining.</returns>
 43    public GroupingBuilder<T> ThenBy(Expression<Func<T, object?>> expression)
 44    {
 645        Add(expression);
 646        return this;
 47    }
 48
 49    /// <summary>
 50    /// Builds the list of grouping properties that have been added to the builder. This method returns a read-only list
 51    /// </summary>
 52    /// <returns>A read-only list of <see cref="IGroupingProperty{T}"/> instances representing the grouping configuratio
 1253    public IReadOnlyList<IGroupingProperty<T>> Build() => _properties;
 54}
 55