5 // Marek Safar (marek.safar@gmail.com)
6 // Alejandro Serrano "Serras" (trupill@yahoo.es)
7 // Jb Evain (jbevain@novell.com)
9 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections.Generic;
33 using System.Linq.Expressions;
34 using System.Reflection;
36 namespace System.Linq {
38 public static class Queryable {
40 static MethodInfo MakeGeneric (MethodBase method, params Type [] parameters)
42 return ((MethodInfo) method).MakeGenericMethod (parameters);
45 static Expression StaticCall (MethodInfo method, params Expression [] expressions)
47 return Expression.Call (null, method, expressions);
50 static TRet Execute<TRet, TSource> (this IQueryable<TSource> source, MethodBase current)
52 return source.Provider.Execute<TRet> (
54 MakeGeneric (current, typeof (TSource)),
58 public static int Count<TSource> (this IQueryable<TSource> source)
60 Check.Source (source);
62 return source.Execute<int, TSource> (MethodBase.GetCurrentMethod ());
65 public static int Count<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
67 Check.SourceAndPredicate (source, predicate);
69 return source.Provider.Execute<int> (
71 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
73 Expression.Quote (predicate)));
76 public static long LongCount<TSource> (this IQueryable<TSource> source)
78 Check.Source (source);
80 return source.Execute<long, TSource> (MethodBase.GetCurrentMethod ());
83 public static long LongCount<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
85 Check.SourceAndPredicate (source, predicate);
87 return source.Provider.Execute<long> (
89 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
91 Expression.Quote (predicate)));
94 public static int Sum (this IQueryable<int> source)
96 Check.Source (source);
98 return source.Provider.Execute<int> (
100 (MethodInfo) MethodBase.GetCurrentMethod (),
104 public static int Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int>> selector)
106 throw new NotImplementedException ();
109 public static int? Sum (this IQueryable<int?> source)
111 throw new NotImplementedException ();
114 public static int? Sum<TSource> (
115 this IQueryable<TSource> source,
116 Func<TSource, int?> selector)
118 throw new NotImplementedException ();
121 public static long Sum (this IQueryable<long> source)
123 throw new NotImplementedException ();
126 public static long Sum<TSource> (
127 this IQueryable<TSource> source,
128 Func<TSource, long> selector)
130 throw new NotImplementedException ();
133 public static long? Sum (this IQueryable<long?> source)
135 throw new NotImplementedException ();
138 public static long? Sum<TSource> (
139 this IQueryable<TSource> source,
140 Func<TSource, long?> selector)
142 throw new NotImplementedException ();
145 public static double Sum (this IQueryable<double> source)
147 throw new NotImplementedException ();
150 public static double Sum<TSource> (
151 this IQueryable<TSource> source,
152 Func<TSource, double> selector)
154 throw new NotImplementedException ();
157 public static double? Sum (this IQueryable<double?> source)
159 throw new NotImplementedException ();
162 public static double? Sum<TSource> (
163 this IQueryable<TSource> source,
164 Func<TSource, double?> selector)
166 throw new NotImplementedException ();
169 public static decimal Sum (this IQueryable<decimal> source)
171 throw new NotImplementedException ();
174 public static decimal Sum<TSource> (
175 this IQueryable<TSource> source,
176 Func<TSource, decimal> selector)
178 throw new NotImplementedException ();
181 public static decimal? Sum (this IQueryable<decimal?> source)
183 throw new NotImplementedException ();
186 public static decimal? Sum<TSource> (
187 this IQueryable<TSource> source,
188 Func<TSource, decimal?> selector)
190 throw new NotImplementedException ();
193 public static int Min (this IQueryable<int> source)
195 throw new NotImplementedException ();
198 public static int? Min (this IQueryable<int?> source)
200 throw new NotImplementedException ();
203 public static long Min (this IQueryable<long> source)
205 throw new NotImplementedException ();
208 public static long? Min (this IQueryable<long?> source)
210 throw new NotImplementedException ();
213 public static double Min (this IQueryable<double> source)
215 throw new NotImplementedException ();
218 public static double? Min (this IQueryable<double?> source)
220 throw new NotImplementedException ();
223 public static decimal Min (this IQueryable<decimal> source)
225 throw new NotImplementedException ();
228 public static decimal? Min (this IQueryable<decimal?> source)
230 throw new NotImplementedException ();
233 public static TSource Min<TSource> (this IQueryable<TSource> source)
235 throw new NotImplementedException ();
238 public static int Min<TSource> (
239 this IQueryable<TSource> source,
240 Func<TSource, int> selector)
242 throw new NotImplementedException ();
245 public static int? Min<TSource> (
246 this IQueryable<TSource> source,
247 Func<TSource, int?> selector)
249 throw new NotImplementedException ();
252 public static long Min<TSource> (
253 this IQueryable<TSource> source,
254 Func<TSource, long> selector)
256 throw new NotImplementedException ();
259 public static long? Min<TSource> (
260 this IQueryable<TSource> source,
261 Func<TSource, long?> selector)
263 throw new NotImplementedException ();
266 public static double Min<TSource> (
267 this IQueryable<TSource> source,
268 Func<TSource, double> selector)
270 throw new NotImplementedException ();
273 public static double? Min<TSource> (
274 this IQueryable<TSource> source,
275 Func<TSource, double?> selector)
277 throw new NotImplementedException ();
280 public static decimal Min<TSource> (
281 this IQueryable<TSource> source,
282 Func<TSource, decimal> selector)
284 throw new NotImplementedException ();
287 public static decimal? Min<TSource> (
288 this IQueryable<TSource> source,
289 Func<TSource, decimal?> selector)
291 throw new NotImplementedException ();
294 public static TResult Min<TSource, TResult> (
295 this IQueryable<TSource> source,
296 Func<TSource, TResult> selector)
298 throw new NotImplementedException ();
301 public static int Max (this IQueryable<int> source)
303 throw new NotImplementedException ();
306 public static int? Max (this IQueryable<int?> source)
308 throw new NotImplementedException ();
311 public static long Max (this IQueryable<long> source)
313 throw new NotImplementedException ();
316 public static long? Max (this IQueryable<long?> source)
318 throw new NotImplementedException ();
321 public static double Max (
322 this IQueryable<double> source)
324 throw new NotImplementedException ();
327 public static double? Max (
328 this IQueryable<double?> source)
330 throw new NotImplementedException ();
333 public static decimal Max (
334 this IQueryable<decimal> source)
336 throw new NotImplementedException ();
339 public static decimal? Max (
340 this IQueryable<decimal?> source)
342 throw new NotImplementedException ();
345 public static TSource Max<TSource> (
346 this IQueryable<TSource> source)
348 throw new NotImplementedException ();
351 public static int Max<TSource> (
352 this IQueryable<TSource> source,
353 Func<TSource, int> selector)
355 throw new NotImplementedException ();
358 public static int? Max<TSource> (
359 this IQueryable<TSource> source,
360 Func<TSource, int?> selector)
362 throw new NotImplementedException ();
365 public static long Max<TSource> (
366 this IQueryable<TSource> source,
367 Func<TSource, long> selector)
369 throw new NotImplementedException ();
372 public static long? Max<TSource> (
373 this IQueryable<TSource> source,
374 Func<TSource, long?> selector)
376 throw new NotImplementedException ();
379 public static double Max<TSource> (
380 this IQueryable<TSource> source,
381 Func<TSource, double> selector)
383 throw new NotImplementedException ();
386 public static double? Max<TSource> (
387 this IQueryable<TSource> source,
388 Func<TSource, double?> selector)
390 throw new NotImplementedException ();
393 public static decimal Max<TSource> (
394 this IQueryable<TSource> source,
395 Func<TSource, decimal> selector)
397 throw new NotImplementedException ();
400 public static decimal? Max<TSource> (
401 this IQueryable<TSource> source,
402 Func<TSource, decimal?> selector)
404 throw new NotImplementedException ();
407 public static TResult Max<TSource, TResult> (
408 this IQueryable<TSource> source,
409 Func<TSource, TResult> selector)
411 throw new NotImplementedException ();
414 public static double Average (this IQueryable<int> source)
416 throw new NotImplementedException ();
419 public static double? Average (this IQueryable<int?> source)
421 throw new NotImplementedException ();
424 public static double Average (this IQueryable<long> source)
426 throw new NotImplementedException ();
429 public static double? Average (this IQueryable<long?> source)
431 throw new NotImplementedException ();
434 public static double Average (this IQueryable<double> source)
436 throw new NotImplementedException ();
439 public static double? Average (this IQueryable<double?> source)
441 throw new NotImplementedException ();
444 public static decimal Average (this IQueryable<decimal> source)
446 throw new NotImplementedException ();
449 public static decimal? Average (this IQueryable<decimal?> source)
451 throw new NotImplementedException ();
454 public static double Average<TSource> (this IQueryable<TSource> source,
455 Func<TSource, int> selector)
457 throw new NotImplementedException ();
460 public static double? Average<TSource> (this IQueryable<TSource> source,
461 Func<TSource, int?> selector)
463 throw new NotImplementedException ();
466 public static double Average<TSource> (this IQueryable<TSource> source,
467 Func<TSource, long> selector)
469 throw new NotImplementedException ();
472 public static double? Average<TSource> (this IQueryable<TSource> source,
473 Func<TSource, long?> selector)
475 throw new NotImplementedException ();
478 public static double Average<TSource> (this IQueryable<TSource> source,
479 Func<TSource, double> selector)
481 throw new NotImplementedException ();
484 public static double? Average<TSource> (this IQueryable<TSource> source,
485 Func<TSource, double?> selector)
487 throw new NotImplementedException ();
490 public static decimal Average<TSource> (this IQueryable<TSource> source,
491 Func<TSource, decimal> selector)
493 throw new NotImplementedException ();
496 public static decimal? Average<TSource> (this IQueryable<TSource> source,
497 Func<TSource, decimal?> selector)
499 throw new NotImplementedException ();
502 public static TSource Aggregate<TSource> (
503 this IQueryable<TSource> source,
504 Func<TSource, TSource, TSource> func)
506 throw new NotImplementedException ();
509 public static U Aggregate<TSource, U> (
510 this IQueryable<TSource> source,
512 Func<U, TSource, U> func)
514 throw new NotImplementedException ();
517 public static IEnumerable<TSource> Concat<TSource> (
518 this IQueryable<TSource> first,
519 IEnumerable<TSource> second)
521 throw new NotImplementedException ();
524 public static IEnumerable<TResult> OfType<TResult> (this IQueryable source)
526 throw new NotImplementedException ();
529 public static IEnumerable<TResult> Cast<TResult> (this IQueryable source)
531 throw new NotImplementedException ();
534 public static TSource First<TSource> (this IQueryable<TSource> source)
536 throw new NotImplementedException ();
539 public static TSource First<TSource> (
540 this IQueryable<TSource> source,
541 Func<TSource, bool> predicate)
543 throw new NotImplementedException ();
546 public static TSource FirstOrDefault<TSource> (this IQueryable<TSource> source)
548 throw new NotImplementedException ();
551 public static TSource FirstOrDefault<TSource> (
552 this IQueryable<TSource> source,
553 Func<TSource, bool> predicate)
555 throw new NotImplementedException ();
558 public static TSource Last<TSource> (this IQueryable<TSource> source)
560 throw new NotImplementedException ();
563 public static TSource Last<TSource> (
564 this IQueryable<TSource> source,
565 Func<TSource, bool> predicate)
567 throw new NotImplementedException ();
570 public static TSource LastOrDefault<TSource> (this IQueryable<TSource> source)
572 throw new NotImplementedException ();
575 public static TSource LastOrDefault<TSource> (
576 this IQueryable<TSource> source,
577 Func<TSource, bool> predicate)
579 throw new NotImplementedException ();
582 public static TSource Single<TSource> (this IQueryable<TSource> source)
584 throw new NotImplementedException ();
587 public static TSource Single<TSource> (
588 this IQueryable<TSource> source,
589 Func<TSource, bool> predicate)
591 throw new NotImplementedException ();
594 public static TSource SingleOrDefault<TSource> (this IQueryable<TSource> source)
596 throw new NotImplementedException ();
599 public static TSource SingleOrDefault<TSource> (
600 this IQueryable<TSource> source,
601 Func<TSource, bool> predicate)
603 throw new NotImplementedException ();
606 public static TSource ElementAt<TSource> (
607 this IQueryable<TSource> source,
610 throw new NotImplementedException ();
613 public static TSource ElementAtOrDefault<TSource> (
614 this IQueryable<TSource> source,
617 throw new NotImplementedException ();
620 public static IEnumerable<TSource> DefaultIfEmpty<TSource> (
621 this IQueryable<TSource> source)
623 throw new NotImplementedException ();
626 public static IEnumerable<TSource> DefaultIfEmpty<TSource> (
627 this IQueryable<TSource> source,
628 TSource defaultValue)
630 throw new NotImplementedException ();
633 public static IEnumerable<TSource> Repeat<TSource> (this TSource element, int count)
635 throw new NotImplementedException ();
638 private static List<TSource> ContainsGroup<K, TSource>(
639 Dictionary<K, List<TSource>> items, K key, IEqualityComparer<K> comparer)
641 throw new NotImplementedException ();
644 public static IQueryable<IGrouping<K, TSource>> GroupBy<TSource, K> (
645 this IQueryable<TSource> source,
646 Func<TSource, K> keySelector)
648 throw new NotImplementedException ();
651 public static IQueryable<IGrouping<K, E>> GroupBy<TSource, K, E> (
652 this IQueryable<TSource> source,
653 Func<TSource, K> keySelector,
654 Func<TSource, E> elementSelector)
656 throw new NotImplementedException ();
659 public static IEnumerable<IGrouping<K, E>> GroupBy<TSource, K, E> (
660 this IQueryable<TSource> source,
661 Func<TSource, K> keySelector,
662 Func<TSource, E> elementSelector,
663 IEqualityComparer<K> comparer)
665 throw new NotImplementedException ();
668 public static IOrderedQueryable<TSource> OrderBy<TSource, TKey> (
669 this IQueryable<TSource> source,
670 Func<TSource, TKey> keySelector)
672 throw new NotImplementedException ();
675 public static IOrderedQueryable<TSource> OrderBy<TSource, TKey> (
676 this IQueryable<TSource> source,
677 Func<TSource, TKey> keySelector,
678 IComparer<TKey> comparer)
680 throw new NotImplementedException ();
683 public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey> (
684 this IQueryable<TSource> source,
685 Func<TSource, TKey> keySelector)
687 throw new NotImplementedException ();
690 public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey> (
691 this IQueryable<TSource> source,
692 Func<TSource, TKey> keySelector,
693 IComparer<TKey> comparer)
695 throw new NotImplementedException ();
698 public static IOrderedQueryable<TSource> ThenBy<TSource, TKey> (
699 this IOrderedQueryable<TSource> source,
700 Func<TSource, TKey> keySelector)
702 throw new NotImplementedException ();
705 public static IOrderedQueryable<TSource> ThenBy<TSource, TKey> (
706 this IOrderedQueryable<TSource> source,
707 Func<TSource, TKey> keySelector,
708 IComparer<TKey> comparer)
710 throw new NotImplementedException ();
713 public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey> (
714 this IOrderedQueryable<TSource> source,
715 Func<TSource, TKey> keySelector)
717 throw new NotImplementedException ();
720 public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey> (
721 this IOrderedQueryable<TSource> source,
722 Func<TSource, TKey> keySelector,
723 IComparer<TKey> comparer)
725 throw new NotImplementedException ();
728 public static IQueryable<TSource> Reverse<TSource> (
729 this IQueryable<TSource> source)
731 throw new NotImplementedException ();
734 public static IEnumerable<TSource> Take<TSource> (
735 this IQueryable<TSource> source,
738 throw new NotImplementedException ();
741 public static IEnumerable<TSource> Skip<TSource> (
742 this IQueryable<TSource> source,
745 throw new NotImplementedException ();
748 public static IEnumerable<TSource> TakeWhile<TSource> (
749 this IQueryable<TSource> source,
750 Func<TSource, bool> predicate)
752 throw new NotImplementedException ();
755 public static IEnumerable<TSource> TakeWhile<TSource> (
756 this IQueryable<TSource> source,
757 Func<TSource, int, bool> predicate)
759 throw new NotImplementedException ();
762 public static IEnumerable<TSource> SkipWhile<TSource> (
763 this IQueryable<TSource> source,
764 Func<TSource, bool> predicate)
766 throw new NotImplementedException ();
769 public static IEnumerable<TSource> SkipWhile<TSource> (
770 this IQueryable<TSource> source,
771 Func<TSource, int, bool> predicate)
773 throw new NotImplementedException ();
776 public static IEnumerable<TResult> Select<TSource, TResult> (
777 this IQueryable<TSource> source,
778 Func<TSource, TResult> selector)
780 throw new NotImplementedException ();
783 public static IEnumerable<TResult> Select<TSource, TResult> (
784 this IQueryable<TSource> source,
785 Func<TSource, int, TResult> selector)
787 throw new NotImplementedException ();
790 public static IEnumerable<TResult> SelectMany<TSource, TResult> (
791 this IQueryable<TSource> source,
792 Func<TSource, IQueryable<TResult>> selector)
794 throw new NotImplementedException ();
797 public static IEnumerable<TResult> SelectMany<TSource, TResult> (
798 this IQueryable<TSource> source,
799 Func<TSource, int, IQueryable<TResult>> selector)
801 throw new NotImplementedException ();
804 public static bool Any<TSource> (this IQueryable<TSource> source)
806 throw new NotImplementedException ();
809 public static bool Any<TSource> (
810 this IQueryable<TSource> source,
811 Func<TSource, bool> predicate)
813 throw new NotImplementedException ();
816 public static bool All<TSource> (
817 this IQueryable<TSource> source,
818 Func<TSource, bool> predicate)
820 throw new NotImplementedException ();
823 public static bool Contains<TSource> (this IQueryable<TSource> source, TSource value)
825 throw new NotImplementedException ();
828 public static IEnumerable<TSource> Where<TSource> (
829 this IQueryable<TSource> source,
830 Func<TSource, bool> predicate)
832 throw new NotImplementedException ();
835 public static IEnumerable<TSource> Where<TSource> (
836 this IQueryable<TSource> source,
837 Func<TSource, int, bool> predicate)
839 throw new NotImplementedException ();
842 public static IEnumerable<V> Join<TSource, U, K, V> (
843 this IQueryable<TSource> outer,
845 Func<TSource, K> outerKeySelector,
846 Func<U, K> innerKeySelector,
847 Func<TSource, U, V> resultSelector)
849 throw new NotImplementedException ();