private Expression VisitOrderAscendingMethod(Expression m) { void InspectOrdering(Expression e) { MethodCallExpression o = e as MethodCallExpression ?? throw new AuthenticationException($"Invalid expression type {e.GetType().Name}"); Expression lambdaBody = o.GetLambdaBody(); switch (o.Method.Name) { case "OrderBy": Visit(o.Arguments[0]); _sb.Append("\"sort\":["); Visit(lambdaBody); break; case "OrderByDescending": throw new InvalidOperationException("Cannot order in different directions."); case "ThenBy": InspectOrdering(o.Arguments[0]); Visit(lambdaBody); break; default: return; } _sb.Append(","); } InspectOrdering(m); _sb.Length--; _sb.Append("],"); return(m); }
private Expression VisitSelectMethod(MethodCallExpression m) { Visit(m.Arguments[0]); _sb.Append("\"fields\":["); Expression lambdaBody = m.GetLambdaBody(); if (lambdaBody is NewExpression n) { foreach (Expression a in n.Arguments) { Visit(a); _sb.Append(","); } _sb.Length--; } else if (lambdaBody is MemberExpression mb) { Visit(mb); } else { throw new NotSupportedException($"The expression of type {lambdaBody} is not supported in the Select method."); } _sb.Append("],"); return(m); }
private Expression VisitAllMethod(MethodCallExpression m) { _sb.Append("{"); Visit(m.Arguments[0]); _sb.Append(":{\"$allMatch\":"); Expression lambdaBody = m.GetLambdaBody(); Visit(lambdaBody); _sb.Append("}}"); return(m); }
private Expression VisitWhereMethod(MethodCallExpression m) { Visit(m.Arguments[0]); _sb.Append("\"selector\":"); Expression lambdaBody = m.GetLambdaBody(); Visit(lambdaBody); _sb.Append(","); _isSelectorSet = true; return(m); }