/// <summary> /// Invokes the Count extension method on the wrapped query via reflection /// </summary> /// <typeparam name="TElement">The element type of the wrapped query</typeparam> /// <param name="query">The wrapped query</param> /// <returns>The results of the count extension method</returns> public static int Count <TElement>(this WrappedDataServiceQuery <TElement> query) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(query, "query"); var countMethod = typeof(Queryable).GetMethods(true, true).SingleOrDefault(m => m.Name == "Count" && m.GetParameters().Length == 1); ExceptionUtilities.CheckObjectNotNull(countMethod, "Could not find method 'Count' on type 'Queryable'"); countMethod = countMethod.MakeGenericMethod(query.ElementType); var product = query.Product; return((int)countMethod.Invoke(null, new object[] { product })); }
/// <summary> /// Invokes the Skip extension method on the wrapped query via reflection /// </summary> /// <typeparam name="TElement">The element type of the wrapped query</typeparam> /// <param name="query">The wrapped query</param> /// <param name="count">The number of elements to skip</param> /// <returns>The wrapped query after calling Skip</returns> public static WrappedDataServiceQuery <TElement> Skip <TElement>(this WrappedDataServiceQuery <TElement> query, int count) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(query, "query"); var skipMethod = typeof(Queryable).GetMethod("Skip", true, true); ExceptionUtilities.CheckObjectNotNull(skipMethod, "Could not find method 'Skip' on type 'Queryable'"); skipMethod = skipMethod.MakeGenericMethod(query.ElementType); var product = query.Product; product = skipMethod.Invoke(null, new object[] { product, count }); return(query.Scope.Wrap <WrappedDataServiceQuery <TElement> >(product)); }
/// <summary> /// Initializes a new instance of the EventsTracker class. /// </summary> /// <param name="wrapType">The wrapper type.</param> public EventsTracker(WrappedDataServiceQuery wrapType) { this.wrapperType = wrapType; }
/// <summary> /// Extension method to perform sync/async version of DataServiceQuery.Execute dynamically /// </summary> /// <typeparam name="TElement">The element type of the wrapped results</typeparam> /// <param name="query">The query to execute</param> /// <param name="continuation">The asynchronous continuation</param> /// <param name="async">A value indicating whether or not to use async API</param> /// <param name="onCompletion">A callback for when the call completes</param> public static void Execute <TElement>(this WrappedDataServiceQuery <TElement> query, IAsyncContinuation continuation, bool async, Action <WrappedIEnumerable <TElement> > onCompletion) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(query, "query"); AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedIEnumerable <TElement> >(continuation, async, () => query.Execute(), c => query.BeginExecute(c, null), r => query.EndExecute(r), onCompletion); }