public static Expression MergeExpression(QueryExpression.Operations op, Expression left, Expression right) { try { switch (op) { case QueryExpression.Operations.Equal: return(Expression.Equal(left, right)); case QueryExpression.Operations.GreaterThan: return(Expression.GreaterThan(left, right)); case QueryExpression.Operations.GreaterThanOrEqual: return(Expression.GreaterThanOrEqual(left, right)); case QueryExpression.Operations.LessThan: return(Expression.LessThan(left, right)); case QueryExpression.Operations.LessThanOrEqual: return(Expression.LessThanOrEqual(left, right)); case QueryExpression.Operations.NotEqual: return(Expression.NotEqual(left, right)); case QueryExpression.Operations.IsChildFrom: MethodInfo mInfo = right.Type.GetMethod("Contains"); return(Expression.Call(right, mInfo, left)); case QueryExpression.Operations.Like: MethodInfo mInfoL = right.Type.GetMethod("Contains"); return(Expression.Call(right, mInfoL, left)); default: throw new ArgumentException("parameter: op is not correct"); } } catch (Exception e) { throw e; } }
private QueryExpression GetQueryExpression(QueryExpressionInfo queryExpressionInfo) { if (queryExpressionInfo == null) { return(null); } QueryExpression qe = new QueryExpression(); qe.PropertyName = queryExpressionInfo.PropertyName; qe.QueryType = queryExpressionInfo.QueryType; qe.RelatedType = queryExpressionInfo.RelatedType == "And" ? QueryExpression.RelationType.And : QueryExpression.RelationType.Or; QueryExpression.Operations op = QueryExpression.Operations.Equal; if (queryExpressionInfo.PropertyName == QueryExpression.Operations.GreaterThan.ToString()) { op = QueryExpression.Operations.GreaterThan; } else if (queryExpressionInfo.PropertyName == QueryExpression.Operations.GreaterThanOrEqual.ToString()) { op = QueryExpression.Operations.GreaterThanOrEqual; } else if (queryExpressionInfo.PropertyName == QueryExpression.Operations.LessThan.ToString()) { op = QueryExpression.Operations.LessThan; } else if (queryExpressionInfo.PropertyName == QueryExpression.Operations.LessThanOrEqual.ToString()) { op = QueryExpression.Operations.LessThanOrEqual; } else if (queryExpressionInfo.PropertyName == QueryExpression.Operations.Like.ToString()) { op = QueryExpression.Operations.Like; } qe.Operation = op; qe.PropertyValue = queryExpressionInfo.PropertyValue; qe.RelatedExpression = GetQueryExpression(queryExpressionInfo.RelatedExpression); return(qe); }