private Expression GetConstantExpression(Expression member, IFilterStatement statement) { var value = statement.Value; if (value == null) { return(null); } Expression constant = Expression.Constant(value); if (value is string) { var trimConstantCall = Expression.Call(constant, helper.trimMethod); constant = Expression.Call(trimConstantCall, helper.toLowerMethod); } else if (statement.ValueIsList()) { var myList = ValueList(statement); constant = Expression.Constant(statement.Operation == Operation.Between ? new ArrayList(myList).ToArray(statement.GetPropertyType()) : myList); } return(constant); }
private Expression GetSafeExpression(Expression member, IFilterStatement statement) { var operation = statement.Operation; var matchType = new OperationHelper().FetchMatchType(operation, statement.MatchType); var constant = GetConstantExpression(member, statement); if (operation != Operation.Between && statement.ValueIsList()) { if (operation == Operation.EqualTo && matchType == MatchType.Any) { return(Expressions[Operation.Contains].Invoke(member, constant)); } else if (operation == Operation.NotEqualTo && matchType == MatchType.All) { return(Expressions[Operation.DoesNotContain].Invoke(member, constant)); } else { var runningExpression = null as Expression; var myList = ValueList(statement); var connector = matchType == MatchType.Any ? Connector.Or : Connector.And; foreach (var item in myList) { Expression loopConstant = Expression.Constant(item); var loopExpression = Expressions[operation].Invoke(member, loopConstant); runningExpression = runningExpression == null ? loopExpression : CombineExpressions(runningExpression, loopExpression, connector); } return(runningExpression ?? Expression.Constant(true)); } } return(Expressions[operation].Invoke(member, constant)); }