-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0078f90
commit 347723b
Showing
1 changed file
with
24 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
// This file is part of the ArmoniK project | ||
// | ||
// Copyright (C) ANEO, 2021-2023. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
|
||
public static class ExpressionExt | ||
{ | ||
/// <summary> | ||
/// Combines two predicate expressions using a logical AND condition | ||
/// Combines two predicate expressions using a logical AND condition | ||
/// </summary> | ||
/// <typeparam name="T"> The type of the input parameter the predicate expressions are evaluated on </typeparam> | ||
/// <param name="expr1"> The first predicate expression to combine </param> | ||
/// <param name="expr2"> The second predicate expression to combine </param> | ||
/// <returns> A new predicate expression that represents the logical AND of the two expressions </returns> | ||
public static Expression<Func<T, bool>> ExpressionAnd<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
Expression<Func<T, bool>> expr2) | ||
=> Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, | ||
expr2.Body), | ||
expr2.Parameters); | ||
|
||
/// <summary> | ||
/// Combines two predicate expressions using a logical OR condition | ||
/// Combines two predicate expressions using a logical OR condition | ||
/// </summary> | ||
/// <typeparam name="T"> The type of the input parameter the predicate expressions are evaluated on </typeparam> | ||
/// <param name="expr1"> The first predicate expression to combine </param> | ||
/// <param name="expr2"> The second predicate expression to combine </param> | ||
/// <returns> A new predicate expression that represents the logical OR of the two expressions </returns> | ||
public static Expression<Func<T, bool>> ExpressionOr<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
Expression<Func<T, bool>> expr2) | ||
=> Expression.Lambda<Func<T, bool>>(Expression.OrElse(expr1.Body, | ||
expr2.Body), | ||
expr2.Parameters); | ||
} | ||
} |