Skip to content

Instantly share code, notes, and snippets.

@madmonkey
Created December 8, 2021 23:29
Show Gist options
  • Save madmonkey/3dfa909746c4a4e4b8abadb10cc15f7d to your computer and use it in GitHub Desktop.
Save madmonkey/3dfa909746c4a4e4b8abadb10cc15f7d to your computer and use it in GitHub Desktop.
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