Created
May 27, 2019 14:40
-
-
Save tornikegomareli/55a636ec6ea34fcf79f266713ab7960f 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
public static Expression<Func<T, bool>> StrToFunc<T>(string propName, string opr, string value, Expression<Func<T, bool>> expr = null) | |
{ | |
Expression<Func<T, bool>> func = null; | |
try | |
{ | |
var type = typeof(T); | |
var prop = type.GetProperty(propName); | |
ParameterExpression tpe = Expression.Parameter(typeof(T)); | |
Expression left = Expression.Property(tpe, prop); | |
Expression right = Expression.Convert(ToExprConstant(prop, value), prop.PropertyType); | |
Expression<Func<T, bool>> innerExpr = Expression.Lambda<Func<T, bool>>(ApplyFilter(opr, left, right), tpe); | |
if (expr != null) | |
innerExpr = innerExpr.And(expr); | |
func = innerExpr; | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine(ex.Message); | |
} | |
return func; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment