public Func <object, Expression <Func <T, bool> > > GetPredicateBuilder <T>(MemberExpression propertyPath) { return(valueToCheck => { ConstantExpression valueToCheckConstant = Expression.Constant(valueToCheck); MethodCallExpression indexOfCall = Expression.Call(Expression.Coalesce(propertyPath, Expression.Constant(String.Empty)), _indexOfMethod, valueToCheckConstant, Expression.Constant(StringComparison.InvariantCultureIgnoreCase)); var operation = _negate ? ExpressionType.LessThan : ExpressionType.GreaterThanOrEqual; BinaryExpression comparison = Expression.MakeBinary(operation, indexOfCall, Expression.Constant(0)); ParameterExpression lambdaParameter = propertyPath.GetParameter <T>(); return Expression.Lambda <Func <T, bool> >(comparison, lambdaParameter); }); }
public Func <object, Expression <Func <T, bool> > > GetPredicateBuilder <T>(MemberExpression propertyPath) { return(expected => { Debug.WriteLine("Building expression for " + _comparisonType); ConstantExpression expectedHolder = propertyPath.Member is PropertyInfo ? Expression.Constant(expected, propertyPath.Member.As <PropertyInfo>().PropertyType) : Expression.Constant(expected); BinaryExpression comparison = Expression.MakeBinary(_comparisonType, propertyPath, expectedHolder); ParameterExpression lambdaParameter = propertyPath.GetParameter <T>(); return Expression.Lambda <Func <T, bool> >(comparison, lambdaParameter); }); }
public Func <object, Expression <Func <T, bool> > > GetPredicateBuilder <T>(MemberExpression propertyPath) { return(valueToCheck => { ConstantExpression valueToCheckConstant = Expression.Constant(valueToCheck); BinaryExpression binaryExpression = Expression.Coalesce(propertyPath, Expression.Constant(string.Empty)); ConstantExpression invariantCulture = Expression.Constant(StringComparison.InvariantCultureIgnoreCase); Expression expression = Expression.Call(binaryExpression, _method, valueToCheckConstant, invariantCulture); if (_negate) { expression = Expression.Not(expression); } ParameterExpression lambdaParameter = propertyPath.GetParameter <T>(); return Expression.Lambda <Func <T, bool> >(expression, lambdaParameter); }); }