Created
December 8, 2021 23:29
-
-
Save madmonkey/3dfa909746c4a4e4b8abadb10cc15f7d to your computer and use it in GitHub Desktop.
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
static class LinqExtensions | |
{ | |
public static IQueryable<TSource> WhereIf<TSource>( | |
this IQueryable<TSource> source, | |
bool condition, | |
Expression<Func<TSource, bool>> predicate) | |
{ | |
return condition ? source.Where(predicate) : source; | |
} | |
public static List<T> Append<T>(this List<T> list, params T[] values) | |
{ | |
list.AddRange(values); | |
return list; | |
} | |
public static List<T> AppendIf<T>(this List<T> list, bool condition, params T[] values) | |
{ | |
return condition ? list.Append(values) : list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment