< Summary

Information
Class: Elsa.Extensions.EnumerableExtensions
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Extensions/EnumerableExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 62
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Paginate(...)0%7280%
Paginate(...)0%7280%
IsEqualTo(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Extensions/EnumerableExtensions.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using JetBrains.Annotations;
 3
 4// ReSharper disable once CheckNamespace
 5namespace Elsa.Extensions;
 6
 7/// <summary>
 8/// Extension methods for <see cref="IEnumerable{T}"/>.
 9/// </summary>
 10[PublicAPI]
 11public static class EnumerableExtensions
 12{
 13    /// <summary>
 14    /// Paginates the enumerable.
 15    /// </summary>
 16    /// <param name="enumerable">The enumerable to paginate.</param>
 17    /// <param name="projection">The projection to apply to the enumerable.</param>
 18    /// <param name="pageArgs">The pagination arguments.</param>
 19    /// <typeparam name="T">The type of the enumerable.</typeparam>
 20    /// <typeparam name="TTarget">The type of the projection.</typeparam>
 21    /// <returns>A page of the projected enumerable.</returns>
 22    public static Page<TTarget> Paginate<T, TTarget>(this IEnumerable<T> enumerable, Func<T, TTarget> projection, PageAr
 23    {
 024        var items = enumerable.ToList();
 025        var count = items.Count;
 26
 027        if (pageArgs?.Offset != null) items = items.Skip(pageArgs.Offset.Value).ToList();
 028        if (pageArgs?.Limit != null) items = items.Take(pageArgs.Limit.Value).ToList();
 29
 030        var results = items.Select(projection).ToList();
 031        return Page.Of(results, count);
 32    }
 33
 34    /// <summary>
 35    /// Paginates the enumerable.
 36    /// </summary>
 37    /// <param name="enumerable">The enumerable to paginate.</param>
 38    /// <param name="pageArgs">The pagination arguments.</param>
 39    /// <typeparam name="T">The type of the enumerable.</typeparam>
 40    /// <returns>A page of the enumerable.</returns>
 41    public static Page<T> Paginate<T>(this IEnumerable<T> enumerable, PageArgs? pageArgs = default)
 42    {
 043        var items = enumerable.ToList();
 044        var count = items.Count;
 45
 046        if (pageArgs?.Offset != null) items = items.Skip(pageArgs.Offset.Value).ToList();
 047        if (pageArgs?.Limit != null) items = items.Take(pageArgs.Limit.Value).ToList();
 48
 049        var results = items.ToList();
 050        return Page.Of(results, count);
 51    }
 52
 53    /// <summary>
 54    /// Returns a value indicating whether two lists are equal.
 55    /// </summary>
 56    /// <param name="list1">The first list.</param>
 57    /// <param name="list2">The second list.</param>
 58    /// <typeparam name="T">The type of the items in the lists.</typeparam>
 59    /// <returns>True if the lists are equal, otherwise false.</returns>
 060    public static bool IsEqualTo<T>(this IEnumerable<T> list1, IEnumerable<T> list2) => list1.OrderBy(g => g).SequenceEq
 61
 62}