Skip to content

Instantly share code, notes, and snippets.

@johnw86
Last active November 30, 2015 21:53
Show Gist options
  • Save johnw86/eff12838f4b69cfb04de to your computer and use it in GitHub Desktop.
Save johnw86/eff12838f4b69cfb04de to your computer and use it in GitHub Desktop.
/* Basic equals expression */
//Line by line
ParameterExpression pe = Expression.Parameter(typeof(Object), "x");
Expression left = Expression.Property(pe, typeof(Object).GetProperty("PropertyName"));
Expression right = Expression.Constant("value");
Expression expression = Expression.Equal(left, right);
var lambda = Expression.Lambda<Func<Object, bool>>(expression, pe);
// Short hand
var param = Expression.Parameter(typeof(Object), "x");
var exp = Expression.Lambda<Func<Object, bool>>(
Expression.Equal(
Expression.Property(param, "PropertyName"),
Expression.Constant("value")
),
param
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment