< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: Microsoft.EntityFrameworkCore.DataCollectionExtensions
Assembly: ZhEaIsNsAaBn.Infrastructure.Core
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/Extensions/DataCollectionExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 50
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
OrderByProperty(...)0%7280%
OrderByDirection(...)0%620%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/Extensions/DataCollectionExtensions.cs

#LineLine coverage
 1using System.Reflection;
 2
 3// ReSharper disable once CheckNamespace
 4namespace Microsoft.EntityFrameworkCore;
 5
 6/// <summary>Sorting helpers for <see cref="IQueryable{T}"/> driven by request values.</summary>
 7public static class DataCollectionExtensions
 8{
 9    /// <summary>
 10    /// Sorts by the property or field named <paramref name="propertyName"/> (case-insensitive). The query is returned
 11    /// unsorted when the name is blank or <typeparamref name="T"/> has no such member, so a request value can be passed
 12    /// </summary>
 13    /// <typeparam name="T">The row type.</typeparam>
 14    /// <param name="source">The query.</param>
 15    /// <param name="propertyName">The member to sort by.</param>
 16    /// <param name="dir">The direction; descending by default.</param>
 17    /// <returns>The sorted query.</returns>
 18    public static IQueryable<T> OrderByProperty< T >( this IQueryable<T> source, string? propertyName, OrderDirection? d
 19    {
 020        ArgumentNullException.ThrowIfNull( source );
 21
 022        if ( string.IsNullOrWhiteSpace( propertyName ) ) { return source; }
 23
 24
 25        const BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase;
 026        var                member = (MemberInfo?) typeof( T ).GetProperty( propertyName, flags ) ?? typeof( T ).GetField
 27
 028        if ( member is null ) { return source; }
 29
 30
 031        var parameter = Expression.Parameter( typeof( T ), "x" );
 032        var selector  = Expression.MakeMemberAccess( parameter, member );
 033        var method    = dir == OrderDirection.Descending ? nameof( Queryable.OrderByDescending ) : nameof( Queryable.Ord
 34
 35
 036        var call = Expression.Call( typeof( Queryable ), method, [ typeof( T ), selector.Type ], source.Expression,
 037                                    Expression.Quote( Expression.Lambda( selector, parameter ) ) );
 38
 39
 040        return source.Provider.CreateQuery<T>( call );
 41    }
 42
 43    /// <summary>Sorts the rows themselves (for queries of simple values).</summary>
 44    /// <typeparam name="T">The row type.</typeparam>
 45    /// <param name="source">The query.</param>
 46    /// <param name="dir">The direction; ascending by default.</param>
 47    /// <returns>The sorted query.</returns>
 48    public static IQueryable<T> OrderByDirection< T >( this IQueryable<T> source, OrderDirection? dir = OrderDirection.A
 049        => dir == OrderDirection.Descending ? source.OrderByDescending( x => x ) : source.OrderBy( x => x );
 50}