/// <summary> /// Called by QueryProvider to execute queries /// </summary> /// <param name="expression">ExpressionTree to parse</param> /// <param name="isEnumerable">Indicates whether expression is enumerable</param> /// <returns>list of objects with query results</returns> public virtual async Task <object> ExecuteAsync <T>(Expression expression, bool isEnumerable) where T : class { // request processor is specific to request type (i.e. Status, User, etc.) var reqProc = CreateRequestProcessor <T>(expression); // get input parameters that go on the REST query URL var parameters = GetRequestParameters(expression, reqProc); // construct REST endpoint, based on input parameters var request = reqProc.BuildUrl(parameters); string results; //process request through Twitter if (typeof(T) == typeof(Streaming)) { results = await TwitterExecutor.QueryTwitterStreamAsync(request).ConfigureAwait(false); } else { results = await TwitterExecutor.QueryTwitterAsync(request, reqProc).ConfigureAwait(false); } if (!ExcludeRawJson) { RawResult = results; } // Transform results into objects var queryableList = reqProc.ProcessResults(results); // Copy the IEnumerable entities to an IQueryable. var queryableItems = queryableList.AsQueryable(); // Copy the expression tree that was passed in, changing only the first // argument of the innermost MethodCallExpression. // -- Transforms IQueryable<T> into List<T>, which is (IEnumerable<T>) var treeCopier = new ExpressionTreeModifier <T>(queryableItems); Expression newExpressionTree = treeCopier.CopyAndModify(expression); // This step creates an IQueryable that executes by replacing Queryable methods with Enumerable methods. if (isEnumerable) { return(queryableItems.Provider.CreateQuery(newExpressionTree)); } return(queryableItems.Provider.Execute <object>(newExpressionTree)); }