< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Extensions.ExpressionExtensions
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Extensions/ExpressionExtensions.cs
Line coverage
71%
Covered lines: 10
Uncovered lines: 4
Coverable lines: 14
Total lines: 83
Line coverage: 71.4%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/6/2026 - 12:15:23 AM Line coverage: 0% (0/12) Branch coverage: 0% (0/4) Total lines: 708/2/2026 - 12:17:28 AM Line coverage: 71.4% (10/14) Branch coverage: 0% (0/4) Total lines: 83 5/6/2026 - 12:15:23 AM Line coverage: 0% (0/12) Branch coverage: 0% (0/4) Total lines: 708/2/2026 - 12:17:28 AM Line coverage: 71.4% (10/14) Branch coverage: 0% (0/4) Total lines: 83

Coverage delta

Coverage delta 72 -72

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Or(...)100%11100%
Or(...)0%620%
Not(...)100%11100%
And(...)100%11100%
And(...)0%620%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Extensions/ExpressionExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Linq.Expressions;
 5
 6namespace Jellyfin.Server.Implementations.Extensions;
 7
 8/// <summary>
 9/// Provides <see cref="Expression"/> extension methods.
 10/// </summary>
 11public static class ExpressionExtensions
 12{
 13    /// <summary>
 14    /// Combines two predicates into a single predicate using a logical OR operation.
 15    /// </summary>
 16    /// <typeparam name="T">The predicate parameter type.</typeparam>
 17    /// <param name="firstPredicate">The first predicate expression to combine.</param>
 18    /// <param name="secondPredicate">The second predicate expression to combine.</param>
 19    /// <returns>A new expression representing the OR combination of the input predicates.</returns>
 20    public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> firstPredicate, Expression<Func<T, bool
 21    {
 222        ArgumentNullException.ThrowIfNull(firstPredicate);
 223        ArgumentNullException.ThrowIfNull(secondPredicate);
 24
 225        var invokedExpression = Expression.Invoke(secondPredicate, firstPredicate.Parameters);
 226        return Expression.Lambda<Func<T, bool>>(Expression.OrElse(firstPredicate.Body, invokedExpression), firstPredicat
 27    }
 28
 29    /// <summary>
 30    /// Combines multiple predicates into a single predicate using a logical OR operation.
 31    /// </summary>
 32    /// <typeparam name="T">The predicate parameter type.</typeparam>
 33    /// <param name="predicates">A collection of predicate expressions to combine.</param>
 34    /// <returns>A new expression representing the OR combination of all input predicates.</returns>
 35    public static Expression<Func<T, bool>> Or<T>(this IEnumerable<Expression<Func<T, bool>>> predicates)
 36    {
 037        ArgumentNullException.ThrowIfNull(predicates);
 38
 039        return predicates.Aggregate((aggregatePredicate, nextPredicate) => aggregatePredicate.Or(nextPredicate));
 40    }
 41
 42    /// <summary>
 43    /// Negates a predicate.
 44    /// </summary>
 45    /// <typeparam name="T">The predicate parameter type.</typeparam>
 46    /// <param name="predicate">The predicate expression to negate.</param>
 47    /// <returns>A new expression representing the negation of the input predicate.</returns>
 48    public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> predicate)
 49    {
 150        ArgumentNullException.ThrowIfNull(predicate);
 51
 152        return Expression.Lambda<Func<T, bool>>(Expression.Not(predicate.Body), predicate.Parameters);
 53    }
 54
 55    /// <summary>
 56    /// Combines two predicates into a single predicate using a logical AND operation.
 57    /// </summary>
 58    /// <typeparam name="T">The predicate parameter type.</typeparam>
 59    /// <param name="firstPredicate">The first predicate expression to combine.</param>
 60    /// <param name="secondPredicate">The second predicate expression to combine.</param>
 61    /// <returns>A new expression representing the AND combination of the input predicates.</returns>
 62    public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> firstPredicate, Expression<Func<T, boo
 63    {
 464        ArgumentNullException.ThrowIfNull(firstPredicate);
 465        ArgumentNullException.ThrowIfNull(secondPredicate);
 66
 467        var invokedExpression = Expression.Invoke(secondPredicate, firstPredicate.Parameters);
 468        return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(firstPredicate.Body, invokedExpression), firstPredica
 69    }
 70
 71    /// <summary>
 72    /// Combines multiple predicates into a single predicate using a logical AND operation.
 73    /// </summary>
 74    /// <typeparam name="T">The predicate parameter type.</typeparam>
 75    /// <param name="predicates">A collection of predicate expressions to combine.</param>
 76    /// <returns>A new expression representing the AND combination of all input predicates.</returns>
 77    public static Expression<Func<T, bool>> And<T>(this IEnumerable<Expression<Func<T, bool>>> predicates)
 78    {
 079        ArgumentNullException.ThrowIfNull(predicates);
 80
 081        return predicates.Aggregate((aggregatePredicate, nextPredicate) => aggregatePredicate.And(nextPredicate));
 82    }
 83}