mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 14:56:30 +00:00
switcher dataset explorer
lat lon -> geopoint correct location for gps if small keypoints number
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds Where true predicate only if result of condition is true.
|
||||
/// If false predicate provided, uses it in case of false result
|
||||
/// Useful for filters, when filters should be applied only when it was set (not NULL)
|
||||
/// </summary>
|
||||
public static IQueryable<TSource> WhereIf<TSource>(this IQueryable<TSource> query, bool? condition,
|
||||
Expression<Func<TSource, bool>> truePredicate,
|
||||
Expression<Func<TSource, bool>>? falsePredicate = null)
|
||||
{
|
||||
if (!condition.HasValue)
|
||||
return query;
|
||||
|
||||
if (condition.Value)
|
||||
return query.Where(truePredicate);
|
||||
|
||||
return falsePredicate != null
|
||||
? query.Where(falsePredicate)
|
||||
: query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Where true predicate only if result of condition is true.
|
||||
/// If false predicate provided, uses it in case of false result
|
||||
/// Useful for filters, when filters should be applied only when it was set (not NULL)
|
||||
/// </summary>
|
||||
public static IEnumerable<TSource> WhereIf<TSource>(this IEnumerable<TSource> query, bool? condition,
|
||||
Func<TSource, bool> truePredicate,
|
||||
Func<TSource, bool>? falsePredicate = null)
|
||||
{
|
||||
if (!condition.HasValue)
|
||||
return query;
|
||||
|
||||
if (condition.Value)
|
||||
return query.Where(truePredicate);
|
||||
|
||||
return falsePredicate != null
|
||||
? query.Where(falsePredicate)
|
||||
: query;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user