Skip to content

Instantly share code, notes, and snippets.

@arunzer0
arunzer0 / gist:5614fbc59ec3d258df516e9f0029c59b
Created August 13, 2018 12:19 — forked from afreeland/gist:6733381
C#: LINQ Expression Builder dynamic where clause based on filters
public class ExpressionBuilder
{
// Define some of our default filtering options
private static MethodInfo containsMethod = typeof(string).GetMethod("Contains", new[] { typeof(string) });
private static MethodInfo startsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
private static MethodInfo endsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
public static Expression<Func<T, bool>> GetExpression<T>(List<GridHelper.Filter> filters)
{
// No filters passed in #KickIT