private BsonValue BuildMethodCall(MethodCallExpression node) { BsonValue result; if (MongoExpressionVisitor.IsLinqMethod(node) && TryBuildLinqMethodCall(node, out result)) { return(result); } if (node.Object != null && node.Object.Type == typeof(string) && TryBuildStringMethodCall(node, out result)) { return(result); } if (node.Object != null && node.Object.Type.IsGenericType && node.Object.Type.GetGenericTypeDefinition() == typeof(HashSet <>) && TryBuildHashSetMethodCall(node, out result)) { return(result); } if (node.Object != null && node.Method.Name == "CompareTo" && (TypeHelper.ImplementsInterface(node.Object.Type, typeof(IComparable <>)) || TypeHelper.ImplementsInterface(node.Object.Type, typeof(IComparable)))) { return(new BsonDocument("$cmp", new BsonArray(new[] { BuildValue(node.Object), BuildValue(node.Arguments[0]) }))); } if (node.Object != null && node.Method.Name == "Equals" && node.Arguments.Count == 1) { return(new BsonDocument("$eq", new BsonArray(new[] { BuildValue(node.Object), BuildValue(node.Arguments[0]) }))); } var message = string.Format("{0} of type {1} is an unsupported method in a $project or $group pipeline operator.", node.Method.Name, node.Method.DeclaringType); throw new NotSupportedException(message); }
private BsonValue BuildMethodCall(MethodCallExpression node) { if (MongoExpressionVisitor.IsLinqMethod(node, "Select")) { var serializationExpression = node.Arguments[0] as IBsonSerializationInfoExpression; if (serializationExpression != null) { var body = MongoExpressionVisitor.GetLambda(node.Arguments[1]).Body; return(ResolveValue(body)); } } if (node.Type == typeof(string)) { return(BuildStringMethodCall(node)); } var message = string.Format("{0} is an unsupported method in a $project or $group pipeline operator.", node.Method.Name); throw new NotSupportedException(message); }