mscorlib(4.0.0.0) API with additions
ParallelEnumerable.cs
1 using System.Collections;
4 using System.Linq.Parallel;
5 using System.Threading;
7 
8 namespace System.Linq
9 {
11  [global::__DynamicallyInvokable]
12  public static class ParallelEnumerable
13  {
14  private const string RIGHT_SOURCE_NOT_PARALLEL_STR = "The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.";
15 
22  [global::__DynamicallyInvokable]
24  {
25  if (source == null)
26  {
27  throw new ArgumentNullException("source");
28  }
29  return new ParallelEnumerableWrapper<TSource>(source);
30  }
31 
38  [global::__DynamicallyInvokable]
40  {
41  if (source == null)
42  {
43  throw new ArgumentNullException("source");
44  }
45  return new PartitionerQueryOperator<TSource>(source);
46  }
47 
55  [global::__DynamicallyInvokable]
57  {
58  if (source == null)
59  {
60  throw new ArgumentNullException("source");
61  }
62  if (!(source is ParallelEnumerableWrapper<TSource>) && !(source is IParallelPartitionable<TSource>))
63  {
64  PartitionerQueryOperator<TSource> partitionerQueryOperator = source as PartitionerQueryOperator<TSource>;
65  if (partitionerQueryOperator == null)
66  {
67  throw new InvalidOperationException(SR.GetString("ParallelQuery_InvalidAsOrderedCall"));
68  }
69  if (!partitionerQueryOperator.Orderable)
70  {
71  throw new InvalidOperationException(SR.GetString("ParallelQuery_PartitionerNotOrderable"));
72  }
73  }
74  return new OrderingQueryOperator<TSource>(QueryOperator<TSource>.AsQueryOperator(source), orderOn: true);
75  }
76 
83  [global::__DynamicallyInvokable]
84  public static ParallelQuery AsOrdered(this ParallelQuery source)
85  {
86  if (source == null)
87  {
88  throw new ArgumentNullException("source");
89  }
90  ParallelEnumerableWrapper parallelEnumerableWrapper = source as ParallelEnumerableWrapper;
91  if (parallelEnumerableWrapper == null)
92  {
93  throw new InvalidOperationException(SR.GetString("ParallelQuery_InvalidNonGenericAsOrderedCall"));
94  }
95  return new OrderingQueryOperator<object>(QueryOperator<object>.AsQueryOperator(parallelEnumerableWrapper), orderOn: true);
96  }
97 
104  [global::__DynamicallyInvokable]
106  {
107  if (source == null)
108  {
109  throw new ArgumentNullException("source");
110  }
111  return new OrderingQueryOperator<TSource>(QueryOperator<TSource>.AsQueryOperator(source), orderOn: false);
112  }
113 
119  [global::__DynamicallyInvokable]
120  public static ParallelQuery AsParallel(this IEnumerable source)
121  {
122  if (source == null)
123  {
124  throw new ArgumentNullException("source");
125  }
126  return new ParallelEnumerableWrapper(source);
127  }
128 
135  [global::__DynamicallyInvokable]
137  {
138  if (source == null)
139  {
140  throw new ArgumentNullException("source");
141  }
142  ParallelEnumerableWrapper<TSource> parallelEnumerableWrapper = source as ParallelEnumerableWrapper<TSource>;
143  if (parallelEnumerableWrapper != null)
144  {
145  return parallelEnumerableWrapper.WrappedEnumerable;
146  }
147  return source;
148  }
149 
150  internal static ParallelQuery<TSource> WithTaskScheduler<TSource>(this ParallelQuery<TSource> source, TaskScheduler taskScheduler)
151  {
152  if (source == null)
153  {
154  throw new ArgumentNullException("source");
155  }
156  if (taskScheduler == null)
157  {
158  throw new ArgumentNullException("taskScheduler");
159  }
160  QuerySettings empty = QuerySettings.Empty;
161  empty.TaskScheduler = taskScheduler;
162  return new QueryExecutionOption<TSource>(QueryOperator<TSource>.AsQueryOperator(source), empty);
163  }
164 
175  [global::__DynamicallyInvokable]
176  public static ParallelQuery<TSource> WithDegreeOfParallelism<TSource>(this ParallelQuery<TSource> source, int degreeOfParallelism)
177  {
178  if (source == null)
179  {
180  throw new ArgumentNullException("source");
181  }
182  if (degreeOfParallelism < 1 || degreeOfParallelism > 512)
183  {
184  throw new ArgumentOutOfRangeException("degreeOfParallelism");
185  }
186  QuerySettings empty = QuerySettings.Empty;
187  empty.DegreeOfParallelism = degreeOfParallelism;
188  return new QueryExecutionOption<TSource>(QueryOperator<TSource>.AsQueryOperator(source), empty);
189  }
190 
201  [global::__DynamicallyInvokable]
203  {
204  if (source == null)
205  {
206  throw new ArgumentNullException("source");
207  }
208  CancellationTokenRegistration cancellationTokenRegistration = default(CancellationTokenRegistration);
209  try
210  {
211  cancellationTokenRegistration = cancellationToken.Register(delegate
212  {
213  });
214  }
216  {
217  throw new ArgumentException(SR.GetString("ParallelEnumerable_WithCancellation_TokenSourceDisposed"), "cancellationToken");
218  }
219  finally
220  {
221  cancellationTokenRegistration.Dispose();
222  }
223  QuerySettings empty = QuerySettings.Empty;
224  empty.CancellationState = new CancellationState(cancellationToken);
225  return new QueryExecutionOption<TSource>(QueryOperator<TSource>.AsQueryOperator(source), empty);
226  }
227 
238  [global::__DynamicallyInvokable]
240  {
241  if (source == null)
242  {
243  throw new ArgumentNullException("source");
244  }
245  if (executionMode != 0 && executionMode != ParallelExecutionMode.ForceParallelism)
246  {
247  throw new ArgumentException(SR.GetString("ParallelEnumerable_WithQueryExecutionMode_InvalidMode"));
248  }
249  QuerySettings empty = QuerySettings.Empty;
250  empty.ExecutionMode = executionMode;
251  return new QueryExecutionOption<TSource>(QueryOperator<TSource>.AsQueryOperator(source), empty);
252  }
253 
265  [global::__DynamicallyInvokable]
267  {
268  if (source == null)
269  {
270  throw new ArgumentNullException("source");
271  }
272  if (mergeOptions != 0 && mergeOptions != ParallelMergeOptions.AutoBuffered && mergeOptions != ParallelMergeOptions.NotBuffered && mergeOptions != ParallelMergeOptions.FullyBuffered)
273  {
274  throw new ArgumentException(SR.GetString("ParallelEnumerable_WithMergeOptions_InvalidOptions"));
275  }
276  QuerySettings empty = QuerySettings.Empty;
277  empty.MergeOptions = mergeOptions;
278  return new QueryExecutionOption<TSource>(QueryOperator<TSource>.AsQueryOperator(source), empty);
279  }
280 
287  [global::__DynamicallyInvokable]
288  public static ParallelQuery<int> Range(int start, int count)
289  {
290  if (count < 0 || (count > 0 && int.MaxValue - (count - 1) < start))
291  {
292  throw new ArgumentOutOfRangeException("count");
293  }
294  return new RangeEnumerable(start, count);
295  }
296 
304  [global::__DynamicallyInvokable]
305  public static ParallelQuery<TResult> Repeat<TResult>(TResult element, int count)
306  {
307  if (count < 0)
308  {
309  throw new ArgumentOutOfRangeException("count");
310  }
311  return new RepeatEnumerable<TResult>(element, count);
312  }
313 
317  [global::__DynamicallyInvokable]
319  {
320  return System.Linq.Parallel.EmptyEnumerable<TResult>.Instance;
321  }
322 
331  [global::__DynamicallyInvokable]
332  public static void ForAll<TSource>(this ParallelQuery<TSource> source, Action<TSource> action)
333  {
334  if (source == null)
335  {
336  throw new ArgumentNullException("source");
337  }
338  if (action == null)
339  {
340  throw new ArgumentNullException("action");
341  }
342  new ForAllOperator<TSource>(source, action).RunSynchronously();
343  }
344 
354  [global::__DynamicallyInvokable]
355  public static ParallelQuery<TSource> Where<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
356  {
357  if (source == null)
358  {
359  throw new ArgumentNullException("source");
360  }
361  if (predicate == null)
362  {
363  throw new ArgumentNullException("predicate");
364  }
365  return new WhereQueryOperator<TSource>(source, predicate);
366  }
367 
378  [global::__DynamicallyInvokable]
379  public static ParallelQuery<TSource> Where<TSource>(this ParallelQuery<TSource> source, Func<TSource, int, bool> predicate)
380  {
381  if (source == null)
382  {
383  throw new ArgumentNullException("source");
384  }
385  if (predicate == null)
386  {
387  throw new ArgumentNullException("predicate");
388  }
389  return new IndexedWhereQueryOperator<TSource>(source, predicate);
390  }
391 
402  [global::__DynamicallyInvokable]
403  public static ParallelQuery<TResult> Select<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
404  {
405  if (source == null)
406  {
407  throw new ArgumentNullException("source");
408  }
409  if (selector == null)
410  {
411  throw new ArgumentNullException("selector");
412  }
413  return new SelectQueryOperator<TSource, TResult>(source, selector);
414  }
415 
427  [global::__DynamicallyInvokable]
428  public static ParallelQuery<TResult> Select<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, int, TResult> selector)
429  {
430  if (source == null)
431  {
432  throw new ArgumentNullException("source");
433  }
434  if (selector == null)
435  {
436  throw new ArgumentNullException("selector");
437  }
438  return new IndexedSelectQueryOperator<TSource, TResult>(source, selector);
439  }
440 
453  [global::__DynamicallyInvokable]
454  public static ParallelQuery<TResult> Zip<TFirst, TSecond, TResult>(this ParallelQuery<TFirst> first, ParallelQuery<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
455  {
456  if (first == null)
457  {
458  throw new ArgumentNullException("first");
459  }
460  if (second == null)
461  {
462  throw new ArgumentNullException("second");
463  }
464  if (resultSelector == null)
465  {
466  throw new ArgumentNullException("resultSelector");
467  }
468  return new ZipQueryOperator<TFirst, TSecond, TResult>(first, second, resultSelector);
469  }
470 
480  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
481  [global::__DynamicallyInvokable]
482  public static ParallelQuery<TResult> Zip<TFirst, TSecond, TResult>(this ParallelQuery<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
483  {
484  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
485  }
486 
502  [global::__DynamicallyInvokable]
503  public static ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, ParallelQuery<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
504  {
505  return outer.Join(inner, outerKeySelector, innerKeySelector, resultSelector, null);
506  }
507 
523  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
524  [global::__DynamicallyInvokable]
525  public static ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
526  {
527  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
528  }
529 
546  [global::__DynamicallyInvokable]
547  public static ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, ParallelQuery<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
548  {
549  if (outer == null)
550  {
551  throw new ArgumentNullException("outer");
552  }
553  if (inner == null)
554  {
555  throw new ArgumentNullException("inner");
556  }
557  if (outerKeySelector == null)
558  {
559  throw new ArgumentNullException("outerKeySelector");
560  }
561  if (innerKeySelector == null)
562  {
563  throw new ArgumentNullException("innerKeySelector");
564  }
565  if (resultSelector == null)
566  {
567  throw new ArgumentNullException("resultSelector");
568  }
569  return new JoinQueryOperator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
570  }
571 
585  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
586  [global::__DynamicallyInvokable]
587  public static ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
588  {
589  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
590  }
591 
607  [global::__DynamicallyInvokable]
608  public static ParallelQuery<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, ParallelQuery<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
609  {
610  return outer.GroupJoin(inner, outerKeySelector, innerKeySelector, resultSelector, null);
611  }
612 
628  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
629  [global::__DynamicallyInvokable]
630  public static ParallelQuery<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
631  {
632  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
633  }
634 
651  [global::__DynamicallyInvokable]
652  public static ParallelQuery<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, ParallelQuery<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
653  {
654  if (outer == null)
655  {
656  throw new ArgumentNullException("outer");
657  }
658  if (inner == null)
659  {
660  throw new ArgumentNullException("inner");
661  }
662  if (outerKeySelector == null)
663  {
664  throw new ArgumentNullException("outerKeySelector");
665  }
666  if (innerKeySelector == null)
667  {
668  throw new ArgumentNullException("innerKeySelector");
669  }
670  if (resultSelector == null)
671  {
672  throw new ArgumentNullException("resultSelector");
673  }
674  return new GroupJoinQueryOperator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
675  }
676 
690  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
691  [global::__DynamicallyInvokable]
692  public static ParallelQuery<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this ParallelQuery<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
693  {
694  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
695  }
696 
707  [global::__DynamicallyInvokable]
709  {
710  if (source == null)
711  {
712  throw new ArgumentNullException("source");
713  }
714  if (selector == null)
715  {
716  throw new ArgumentNullException("selector");
717  }
718  return new SelectManyQueryOperator<TSource, TResult, TResult>(source, selector, null, null);
719  }
720 
732  [global::__DynamicallyInvokable]
734  {
735  if (source == null)
736  {
737  throw new ArgumentNullException("source");
738  }
739  if (selector == null)
740  {
741  throw new ArgumentNullException("selector");
742  }
743  return new SelectManyQueryOperator<TSource, TResult, TResult>(source, null, selector, null);
744  }
745 
759  [global::__DynamicallyInvokable]
760  public static ParallelQuery<TResult> SelectMany<TSource, TCollection, TResult>(this ParallelQuery<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
761  {
762  if (source == null)
763  {
764  throw new ArgumentNullException("source");
765  }
766  if (collectionSelector == null)
767  {
768  throw new ArgumentNullException("collectionSelector");
769  }
770  if (resultSelector == null)
771  {
772  throw new ArgumentNullException("resultSelector");
773  }
774  return new SelectManyQueryOperator<TSource, TCollection, TResult>(source, collectionSelector, null, resultSelector);
775  }
776 
790  [global::__DynamicallyInvokable]
791  public static ParallelQuery<TResult> SelectMany<TSource, TCollection, TResult>(this ParallelQuery<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
792  {
793  if (source == null)
794  {
795  throw new ArgumentNullException("source");
796  }
797  if (collectionSelector == null)
798  {
799  throw new ArgumentNullException("collectionSelector");
800  }
801  if (resultSelector == null)
802  {
803  throw new ArgumentNullException("resultSelector");
804  }
805  return new SelectManyQueryOperator<TSource, TCollection, TResult>(source, null, collectionSelector, resultSelector);
806  }
807 
818  [global::__DynamicallyInvokable]
819  public static OrderedParallelQuery<TSource> OrderBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
820  {
821  if (source == null)
822  {
823  throw new ArgumentNullException("source");
824  }
825  if (keySelector == null)
826  {
827  throw new ArgumentNullException("keySelector");
828  }
829  return new OrderedParallelQuery<TSource>(new SortQueryOperator<TSource, TKey>(source, keySelector, null, descending: false));
830  }
831 
843  [global::__DynamicallyInvokable]
844  public static OrderedParallelQuery<TSource> OrderBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
845  {
846  if (source == null)
847  {
848  throw new ArgumentNullException("source");
849  }
850  if (keySelector == null)
851  {
852  throw new ArgumentNullException("keySelector");
853  }
854  return new OrderedParallelQuery<TSource>(new SortQueryOperator<TSource, TKey>(source, keySelector, comparer, descending: false));
855  }
856 
867  [global::__DynamicallyInvokable]
868  public static OrderedParallelQuery<TSource> OrderByDescending<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
869  {
870  if (source == null)
871  {
872  throw new ArgumentNullException("source");
873  }
874  if (keySelector == null)
875  {
876  throw new ArgumentNullException("keySelector");
877  }
878  return new OrderedParallelQuery<TSource>(new SortQueryOperator<TSource, TKey>(source, keySelector, null, descending: true));
879  }
880 
892  [global::__DynamicallyInvokable]
893  public static OrderedParallelQuery<TSource> OrderByDescending<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
894  {
895  if (source == null)
896  {
897  throw new ArgumentNullException("source");
898  }
899  if (keySelector == null)
900  {
901  throw new ArgumentNullException("keySelector");
902  }
903  return new OrderedParallelQuery<TSource>(new SortQueryOperator<TSource, TKey>(source, keySelector, comparer, descending: true));
904  }
905 
916  [global::__DynamicallyInvokable]
917  public static OrderedParallelQuery<TSource> ThenBy<TSource, TKey>(this OrderedParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
918  {
919  if (source == null)
920  {
921  throw new ArgumentNullException("source");
922  }
923  if (keySelector == null)
924  {
925  throw new ArgumentNullException("keySelector");
926  }
927  return new OrderedParallelQuery<TSource>((QueryOperator<TSource>)source.OrderedEnumerable.CreateOrderedEnumerable(keySelector, null, descending: false));
928  }
929 
941  [global::__DynamicallyInvokable]
942  public static OrderedParallelQuery<TSource> ThenBy<TSource, TKey>(this OrderedParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
943  {
944  if (source == null)
945  {
946  throw new ArgumentNullException("source");
947  }
948  if (keySelector == null)
949  {
950  throw new ArgumentNullException("keySelector");
951  }
952  return new OrderedParallelQuery<TSource>((QueryOperator<TSource>)source.OrderedEnumerable.CreateOrderedEnumerable(keySelector, comparer, descending: false));
953  }
954 
965  [global::__DynamicallyInvokable]
966  public static OrderedParallelQuery<TSource> ThenByDescending<TSource, TKey>(this OrderedParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
967  {
968  if (source == null)
969  {
970  throw new ArgumentNullException("source");
971  }
972  if (keySelector == null)
973  {
974  throw new ArgumentNullException("keySelector");
975  }
976  return new OrderedParallelQuery<TSource>((QueryOperator<TSource>)source.OrderedEnumerable.CreateOrderedEnumerable(keySelector, null, descending: true));
977  }
978 
990  [global::__DynamicallyInvokable]
991  public static OrderedParallelQuery<TSource> ThenByDescending<TSource, TKey>(this OrderedParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
992  {
993  if (source == null)
994  {
995  throw new ArgumentNullException("source");
996  }
997  if (keySelector == null)
998  {
999  throw new ArgumentNullException("keySelector");
1000  }
1001  return new OrderedParallelQuery<TSource>((QueryOperator<TSource>)source.OrderedEnumerable.CreateOrderedEnumerable(keySelector, comparer, descending: true));
1002  }
1003 
1014  [global::__DynamicallyInvokable]
1015  public static ParallelQuery<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
1016  {
1017  return source.GroupBy(keySelector, null);
1018  }
1019 
1031  [global::__DynamicallyInvokable]
1032  public static ParallelQuery<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
1033  {
1034  if (source == null)
1035  {
1036  throw new ArgumentNullException("source");
1037  }
1038  if (keySelector == null)
1039  {
1040  throw new ArgumentNullException("keySelector");
1041  }
1042  return new GroupByQueryOperator<TSource, TKey, TSource>(source, keySelector, null, comparer);
1043  }
1044 
1057  [global::__DynamicallyInvokable]
1058  public static ParallelQuery<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
1059  {
1060  return source.GroupBy(keySelector, elementSelector, null);
1061  }
1062 
1076  [global::__DynamicallyInvokable]
1077  public static ParallelQuery<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
1078  {
1079  if (source == null)
1080  {
1081  throw new ArgumentNullException("source");
1082  }
1083  if (keySelector == null)
1084  {
1085  throw new ArgumentNullException("keySelector");
1086  }
1087  if (elementSelector == null)
1088  {
1089  throw new ArgumentNullException("elementSelector");
1090  }
1091  return new GroupByQueryOperator<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
1092  }
1093 
1106  [global::__DynamicallyInvokable]
1107  public static ParallelQuery<TResult> GroupBy<TSource, TKey, TResult>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector)
1108  {
1109  if (resultSelector == null)
1110  {
1111  throw new ArgumentNullException("resultSelector");
1112  }
1113  return from grouping in source.GroupBy(keySelector)
1114  select resultSelector(grouping.Key, grouping);
1115  }
1116 
1130  [global::__DynamicallyInvokable]
1131  public static ParallelQuery<TResult> GroupBy<TSource, TKey, TResult>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1132  {
1133  if (resultSelector == null)
1134  {
1135  throw new ArgumentNullException("resultSelector");
1136  }
1137  return from grouping in source.GroupBy(keySelector, comparer)
1138  select resultSelector(grouping.Key, grouping);
1139  }
1140 
1155  [global::__DynamicallyInvokable]
1156  public static ParallelQuery<TResult> GroupBy<TSource, TKey, TElement, TResult>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector)
1157  {
1158  if (resultSelector == null)
1159  {
1160  throw new ArgumentNullException("resultSelector");
1161  }
1162  return from grouping in source.GroupBy(keySelector, elementSelector)
1163  select resultSelector(grouping.Key, grouping);
1164  }
1165 
1181  [global::__DynamicallyInvokable]
1182  public static ParallelQuery<TResult> GroupBy<TSource, TKey, TElement, TResult>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1183  {
1184  if (resultSelector == null)
1185  {
1186  throw new ArgumentNullException("resultSelector");
1187  }
1188  return from grouping in source.GroupBy(keySelector, elementSelector, comparer)
1189  select resultSelector(grouping.Key, grouping);
1190  }
1191 
1192  private static T PerformAggregation<T>(this ParallelQuery<T> source, Func<T, T, T> reduce, T seed, bool seedIsSpecified, bool throwIfEmpty, QueryAggregationOptions options)
1193  {
1194  AssociativeAggregationOperator<T, T, T> associativeAggregationOperator = new AssociativeAggregationOperator<T, T, T>(source, seed, null, seedIsSpecified, reduce, reduce, (T obj) => obj, throwIfEmpty, options);
1195  return associativeAggregationOperator.Aggregate();
1196  }
1197 
1198  private static TAccumulate PerformSequentialAggregation<TSource, TAccumulate>(this ParallelQuery<TSource> source, TAccumulate seed, bool seedIsSpecified, Func<TAccumulate, TSource, TAccumulate> func)
1199  {
1200  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
1201  {
1202  TAccumulate val;
1203  if (seedIsSpecified)
1204  {
1205  val = seed;
1206  }
1207  else
1208  {
1209  if (!enumerator.MoveNext())
1210  {
1211  throw new InvalidOperationException(SR.GetString("NoElements"));
1212  }
1213  val = (TAccumulate)(object)enumerator.Current;
1214  }
1215  while (enumerator.MoveNext())
1216  {
1217  TSource current = enumerator.Current;
1218  try
1219  {
1220  val = func(val, current);
1221  }
1222  catch (ThreadAbortException)
1223  {
1224  throw;
1225  }
1226  catch (Exception ex2)
1227  {
1228  throw new AggregateException(ex2);
1229  }
1230  }
1231  return val;
1232  }
1233  }
1234 
1246  [global::__DynamicallyInvokable]
1247  public static TSource Aggregate<TSource>(this ParallelQuery<TSource> source, Func<TSource, TSource, TSource> func)
1248  {
1249  return source.Aggregate(func, QueryAggregationOptions.AssociativeCommutative);
1250  }
1251 
1252  internal static TSource Aggregate<TSource>(this ParallelQuery<TSource> source, Func<TSource, TSource, TSource> func, QueryAggregationOptions options)
1253  {
1254  if (source == null)
1255  {
1256  throw new ArgumentNullException("source");
1257  }
1258  if (func == null)
1259  {
1260  throw new ArgumentNullException("func");
1261  }
1262  if ((~(QueryAggregationOptions.Associative | QueryAggregationOptions.Commutative) & options) != 0)
1263  {
1264  throw new ArgumentOutOfRangeException("options");
1265  }
1266  if ((options & QueryAggregationOptions.Associative) != QueryAggregationOptions.Associative)
1267  {
1268  return source.PerformSequentialAggregation(default(TSource), seedIsSpecified: false, func);
1269  }
1270  return source.PerformAggregation(func, default(TSource), seedIsSpecified: false, throwIfEmpty: true, options);
1271  }
1272 
1286  [global::__DynamicallyInvokable]
1287  public static TAccumulate Aggregate<TSource, TAccumulate>(this ParallelQuery<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
1288  {
1289  return source.Aggregate(seed, func, QueryAggregationOptions.AssociativeCommutative);
1290  }
1291 
1292  internal static TAccumulate Aggregate<TSource, TAccumulate>(this ParallelQuery<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, QueryAggregationOptions options)
1293  {
1294  if (source == null)
1295  {
1296  throw new ArgumentNullException("source");
1297  }
1298  if (func == null)
1299  {
1300  throw new ArgumentNullException("func");
1301  }
1302  if ((~(QueryAggregationOptions.Associative | QueryAggregationOptions.Commutative) & options) != 0)
1303  {
1304  throw new ArgumentOutOfRangeException("options");
1305  }
1306  return source.PerformSequentialAggregation(seed, seedIsSpecified: true, func);
1307  }
1308 
1324  [global::__DynamicallyInvokable]
1325  public static TResult Aggregate<TSource, TAccumulate, TResult>(this ParallelQuery<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
1326  {
1327  if (source == null)
1328  {
1329  throw new ArgumentNullException("source");
1330  }
1331  if (func == null)
1332  {
1333  throw new ArgumentNullException("func");
1334  }
1335  if (resultSelector == null)
1336  {
1337  throw new ArgumentNullException("resultSelector");
1338  }
1339  TAccumulate arg = source.PerformSequentialAggregation(seed, seedIsSpecified: true, func);
1340  try
1341  {
1342  return resultSelector(arg);
1343  }
1344  catch (ThreadAbortException)
1345  {
1346  throw;
1347  }
1348  catch (Exception ex2)
1349  {
1350  throw new AggregateException(ex2);
1351  }
1352  }
1353 
1370  [global::__DynamicallyInvokable]
1371  public static TResult Aggregate<TSource, TAccumulate, TResult>(this ParallelQuery<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> updateAccumulatorFunc, Func<TAccumulate, TAccumulate, TAccumulate> combineAccumulatorsFunc, Func<TAccumulate, TResult> resultSelector)
1372  {
1373  if (source == null)
1374  {
1375  throw new ArgumentNullException("source");
1376  }
1377  if (updateAccumulatorFunc == null)
1378  {
1379  throw new ArgumentNullException("updateAccumulatorFunc");
1380  }
1381  if (combineAccumulatorsFunc == null)
1382  {
1383  throw new ArgumentNullException("combineAccumulatorsFunc");
1384  }
1385  if (resultSelector == null)
1386  {
1387  throw new ArgumentNullException("resultSelector");
1388  }
1389  return new AssociativeAggregationOperator<TSource, TAccumulate, TResult>(source, seed, null, seedIsSpecified: true, updateAccumulatorFunc, combineAccumulatorsFunc, resultSelector, throwIfEmpty: false, QueryAggregationOptions.AssociativeCommutative).Aggregate();
1390  }
1391 
1408  [global::__DynamicallyInvokable]
1409  public static TResult Aggregate<TSource, TAccumulate, TResult>(this ParallelQuery<TSource> source, Func<TAccumulate> seedFactory, Func<TAccumulate, TSource, TAccumulate> updateAccumulatorFunc, Func<TAccumulate, TAccumulate, TAccumulate> combineAccumulatorsFunc, Func<TAccumulate, TResult> resultSelector)
1410  {
1411  if (source == null)
1412  {
1413  throw new ArgumentNullException("source");
1414  }
1415  if (seedFactory == null)
1416  {
1417  throw new ArgumentNullException("seedFactory");
1418  }
1419  if (updateAccumulatorFunc == null)
1420  {
1421  throw new ArgumentNullException("updateAccumulatorFunc");
1422  }
1423  if (combineAccumulatorsFunc == null)
1424  {
1425  throw new ArgumentNullException("combineAccumulatorsFunc");
1426  }
1427  if (resultSelector == null)
1428  {
1429  throw new ArgumentNullException("resultSelector");
1430  }
1431  return new AssociativeAggregationOperator<TSource, TAccumulate, TResult>(source, default(TAccumulate), seedFactory, seedIsSpecified: true, updateAccumulatorFunc, combineAccumulatorsFunc, resultSelector, throwIfEmpty: false, QueryAggregationOptions.AssociativeCommutative).Aggregate();
1432  }
1433 
1442  [global::__DynamicallyInvokable]
1443  public static int Count<TSource>(this ParallelQuery<TSource> source)
1444  {
1445  if (source == null)
1446  {
1447  throw new ArgumentNullException("source");
1448  }
1449  ParallelEnumerableWrapper<TSource> parallelEnumerableWrapper = source as ParallelEnumerableWrapper<TSource>;
1450  if (parallelEnumerableWrapper != null)
1451  {
1452  ICollection<TSource> collection = parallelEnumerableWrapper.WrappedEnumerable as ICollection<TSource>;
1453  if (collection != null)
1454  {
1455  return collection.Count;
1456  }
1457  }
1458  return new CountAggregationOperator<TSource>(source).Aggregate();
1459  }
1460 
1470  [global::__DynamicallyInvokable]
1471  public static int Count<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
1472  {
1473  if (source == null)
1474  {
1475  throw new ArgumentNullException("source");
1476  }
1477  if (predicate == null)
1478  {
1479  throw new ArgumentNullException("predicate");
1480  }
1481  return new CountAggregationOperator<TSource>(source.Where(predicate)).Aggregate();
1482  }
1483 
1493  [global::__DynamicallyInvokable]
1494  public static long LongCount<TSource>(this ParallelQuery<TSource> source)
1495  {
1496  if (source == null)
1497  {
1498  throw new ArgumentNullException("source");
1499  }
1500  ParallelEnumerableWrapper<TSource> parallelEnumerableWrapper = source as ParallelEnumerableWrapper<TSource>;
1501  if (parallelEnumerableWrapper != null)
1502  {
1503  ICollection<TSource> collection = parallelEnumerableWrapper.WrappedEnumerable as ICollection<TSource>;
1504  if (collection != null)
1505  {
1506  return collection.Count;
1507  }
1508  }
1509  return new LongCountAggregationOperator<TSource>(source).Aggregate();
1510  }
1511 
1522  [global::__DynamicallyInvokable]
1523  public static long LongCount<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
1524  {
1525  if (source == null)
1526  {
1527  throw new ArgumentNullException("source");
1528  }
1529  if (predicate == null)
1530  {
1531  throw new ArgumentNullException("predicate");
1532  }
1533  return new LongCountAggregationOperator<TSource>(source.Where(predicate)).Aggregate();
1534  }
1535 
1543  [global::__DynamicallyInvokable]
1544  public static int Sum(this ParallelQuery<int> source)
1545  {
1546  if (source == null)
1547  {
1548  throw new ArgumentNullException("source");
1549  }
1550  return new IntSumAggregationOperator(source).Aggregate();
1551  }
1552 
1560  [global::__DynamicallyInvokable]
1561  public static int? Sum(this ParallelQuery<int?> source)
1562  {
1563  if (source == null)
1564  {
1565  throw new ArgumentNullException("source");
1566  }
1567  return new NullableIntSumAggregationOperator(source).Aggregate();
1568  }
1569 
1577  [global::__DynamicallyInvokable]
1578  public static long Sum(this ParallelQuery<long> source)
1579  {
1580  if (source == null)
1581  {
1582  throw new ArgumentNullException("source");
1583  }
1584  return new LongSumAggregationOperator(source).Aggregate();
1585  }
1586 
1594  [global::__DynamicallyInvokable]
1595  public static long? Sum(this ParallelQuery<long?> source)
1596  {
1597  if (source == null)
1598  {
1599  throw new ArgumentNullException("source");
1600  }
1601  return new NullableLongSumAggregationOperator(source).Aggregate();
1602  }
1603 
1611  [global::__DynamicallyInvokable]
1612  public static float Sum(this ParallelQuery<float> source)
1613  {
1614  if (source == null)
1615  {
1616  throw new ArgumentNullException("source");
1617  }
1618  return new FloatSumAggregationOperator(source).Aggregate();
1619  }
1620 
1628  [global::__DynamicallyInvokable]
1629  public static float? Sum(this ParallelQuery<float?> source)
1630  {
1631  if (source == null)
1632  {
1633  throw new ArgumentNullException("source");
1634  }
1635  return new NullableFloatSumAggregationOperator(source).Aggregate();
1636  }
1637 
1645  [global::__DynamicallyInvokable]
1646  public static double Sum(this ParallelQuery<double> source)
1647  {
1648  if (source == null)
1649  {
1650  throw new ArgumentNullException("source");
1651  }
1652  return new DoubleSumAggregationOperator(source).Aggregate();
1653  }
1654 
1662  [global::__DynamicallyInvokable]
1663  public static double? Sum(this ParallelQuery<double?> source)
1664  {
1665  if (source == null)
1666  {
1667  throw new ArgumentNullException("source");
1668  }
1669  return new NullableDoubleSumAggregationOperator(source).Aggregate();
1670  }
1671 
1679  [global::__DynamicallyInvokable]
1680  public static decimal Sum(this ParallelQuery<decimal> source)
1681  {
1682  if (source == null)
1683  {
1684  throw new ArgumentNullException("source");
1685  }
1686  return new DecimalSumAggregationOperator(source).Aggregate();
1687  }
1688 
1696  [global::__DynamicallyInvokable]
1697  public static decimal? Sum(this ParallelQuery<decimal?> source)
1698  {
1699  if (source == null)
1700  {
1701  throw new ArgumentNullException("source");
1702  }
1703  return new NullableDecimalSumAggregationOperator(source).Aggregate();
1704  }
1705 
1715  [global::__DynamicallyInvokable]
1716  public static int Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, int> selector)
1717  {
1718  return source.Select(selector).Sum();
1719  }
1720 
1730  [global::__DynamicallyInvokable]
1731  public static int? Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, int?> selector)
1732  {
1733  return source.Select(selector).Sum();
1734  }
1735 
1745  [global::__DynamicallyInvokable]
1746  public static long Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, long> selector)
1747  {
1748  return source.Select(selector).Sum();
1749  }
1750 
1760  [global::__DynamicallyInvokable]
1761  public static long? Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, long?> selector)
1762  {
1763  return source.Select(selector).Sum();
1764  }
1765 
1775  [global::__DynamicallyInvokable]
1776  public static float Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, float> selector)
1777  {
1778  return source.Select(selector).Sum();
1779  }
1780 
1790  [global::__DynamicallyInvokable]
1791  public static float? Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, float?> selector)
1792  {
1793  return source.Select(selector).Sum();
1794  }
1795 
1805  [global::__DynamicallyInvokable]
1806  public static double Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, double> selector)
1807  {
1808  return source.Select(selector).Sum();
1809  }
1810 
1820  [global::__DynamicallyInvokable]
1821  public static double? Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, double?> selector)
1822  {
1823  return source.Select(selector).Sum();
1824  }
1825 
1835  [global::__DynamicallyInvokable]
1836  public static decimal Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal> selector)
1837  {
1838  return source.Select(selector).Sum();
1839  }
1840 
1850  [global::__DynamicallyInvokable]
1851  public static decimal? Sum<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal?> selector)
1852  {
1853  return source.Select(selector).Sum();
1854  }
1855 
1865  [global::__DynamicallyInvokable]
1866  public static int Min(this ParallelQuery<int> source)
1867  {
1868  if (source == null)
1869  {
1870  throw new ArgumentNullException("source");
1871  }
1872  return new IntMinMaxAggregationOperator(source, -1).Aggregate();
1873  }
1874 
1884  [global::__DynamicallyInvokable]
1885  public static int? Min(this ParallelQuery<int?> source)
1886  {
1887  if (source == null)
1888  {
1889  throw new ArgumentNullException("source");
1890  }
1891  return new NullableIntMinMaxAggregationOperator(source, -1).Aggregate();
1892  }
1893 
1903  [global::__DynamicallyInvokable]
1904  public static long Min(this ParallelQuery<long> source)
1905  {
1906  if (source == null)
1907  {
1908  throw new ArgumentNullException("source");
1909  }
1910  return new LongMinMaxAggregationOperator(source, -1).Aggregate();
1911  }
1912 
1922  [global::__DynamicallyInvokable]
1923  public static long? Min(this ParallelQuery<long?> source)
1924  {
1925  if (source == null)
1926  {
1927  throw new ArgumentNullException("source");
1928  }
1929  return new NullableLongMinMaxAggregationOperator(source, -1).Aggregate();
1930  }
1931 
1941  [global::__DynamicallyInvokable]
1942  public static float Min(this ParallelQuery<float> source)
1943  {
1944  if (source == null)
1945  {
1946  throw new ArgumentNullException("source");
1947  }
1948  return new FloatMinMaxAggregationOperator(source, -1).Aggregate();
1949  }
1950 
1960  [global::__DynamicallyInvokable]
1961  public static float? Min(this ParallelQuery<float?> source)
1962  {
1963  if (source == null)
1964  {
1965  throw new ArgumentNullException("source");
1966  }
1967  return new NullableFloatMinMaxAggregationOperator(source, -1).Aggregate();
1968  }
1969 
1979  [global::__DynamicallyInvokable]
1980  public static double Min(this ParallelQuery<double> source)
1981  {
1982  if (source == null)
1983  {
1984  throw new ArgumentNullException("source");
1985  }
1986  return new DoubleMinMaxAggregationOperator(source, -1).Aggregate();
1987  }
1988 
1998  [global::__DynamicallyInvokable]
1999  public static double? Min(this ParallelQuery<double?> source)
2000  {
2001  if (source == null)
2002  {
2003  throw new ArgumentNullException("source");
2004  }
2005  return new NullableDoubleMinMaxAggregationOperator(source, -1).Aggregate();
2006  }
2007 
2017  [global::__DynamicallyInvokable]
2018  public static decimal Min(this ParallelQuery<decimal> source)
2019  {
2020  if (source == null)
2021  {
2022  throw new ArgumentNullException("source");
2023  }
2024  return new DecimalMinMaxAggregationOperator(source, -1).Aggregate();
2025  }
2026 
2036  [global::__DynamicallyInvokable]
2037  public static decimal? Min(this ParallelQuery<decimal?> source)
2038  {
2039  if (source == null)
2040  {
2041  throw new ArgumentNullException("source");
2042  }
2043  return new NullableDecimalMinMaxAggregationOperator(source, -1).Aggregate();
2044  }
2045 
2056  [global::__DynamicallyInvokable]
2057  public static TSource Min<TSource>(this ParallelQuery<TSource> source)
2058  {
2059  if (source == null)
2060  {
2061  throw new ArgumentNullException("source");
2062  }
2063  return AggregationMinMaxHelpers<TSource>.ReduceMin(source);
2064  }
2065 
2077  [global::__DynamicallyInvokable]
2078  public static int Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, int> selector)
2079  {
2080  return source.Select(selector).Min<int>();
2081  }
2082 
2094  [global::__DynamicallyInvokable]
2095  public static int? Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, int?> selector)
2096  {
2097  return source.Select(selector).Min<int?>();
2098  }
2099 
2111  [global::__DynamicallyInvokable]
2112  public static long Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, long> selector)
2113  {
2114  return source.Select(selector).Min<long>();
2115  }
2116 
2128  [global::__DynamicallyInvokable]
2129  public static long? Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, long?> selector)
2130  {
2131  return source.Select(selector).Min<long?>();
2132  }
2133 
2145  [global::__DynamicallyInvokable]
2146  public static float Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, float> selector)
2147  {
2148  return source.Select(selector).Min<float>();
2149  }
2150 
2162  [global::__DynamicallyInvokable]
2163  public static float? Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, float?> selector)
2164  {
2165  return source.Select(selector).Min<float?>();
2166  }
2167 
2179  [global::__DynamicallyInvokable]
2180  public static double Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, double> selector)
2181  {
2182  return source.Select(selector).Min<double>();
2183  }
2184 
2196  [global::__DynamicallyInvokable]
2197  public static double? Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, double?> selector)
2198  {
2199  return source.Select(selector).Min<double?>();
2200  }
2201 
2213  [global::__DynamicallyInvokable]
2214  public static decimal Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal> selector)
2215  {
2216  return source.Select(selector).Min<decimal>();
2217  }
2218 
2230  [global::__DynamicallyInvokable]
2231  public static decimal? Min<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal?> selector)
2232  {
2233  return source.Select(selector).Min<decimal?>();
2234  }
2235 
2248  [global::__DynamicallyInvokable]
2249  public static TResult Min<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
2250  {
2251  return source.Select(selector).Min();
2252  }
2253 
2263  [global::__DynamicallyInvokable]
2264  public static int Max(this ParallelQuery<int> source)
2265  {
2266  if (source == null)
2267  {
2268  throw new ArgumentNullException("source");
2269  }
2270  return new IntMinMaxAggregationOperator(source, 1).Aggregate();
2271  }
2272 
2282  [global::__DynamicallyInvokable]
2283  public static int? Max(this ParallelQuery<int?> source)
2284  {
2285  if (source == null)
2286  {
2287  throw new ArgumentNullException("source");
2288  }
2289  return new NullableIntMinMaxAggregationOperator(source, 1).Aggregate();
2290  }
2291 
2301  [global::__DynamicallyInvokable]
2302  public static long Max(this ParallelQuery<long> source)
2303  {
2304  if (source == null)
2305  {
2306  throw new ArgumentNullException("source");
2307  }
2308  return new LongMinMaxAggregationOperator(source, 1).Aggregate();
2309  }
2310 
2320  [global::__DynamicallyInvokable]
2321  public static long? Max(this ParallelQuery<long?> source)
2322  {
2323  if (source == null)
2324  {
2325  throw new ArgumentNullException("source");
2326  }
2327  return new NullableLongMinMaxAggregationOperator(source, 1).Aggregate();
2328  }
2329 
2339  [global::__DynamicallyInvokable]
2340  public static float Max(this ParallelQuery<float> source)
2341  {
2342  if (source == null)
2343  {
2344  throw new ArgumentNullException("source");
2345  }
2346  return new FloatMinMaxAggregationOperator(source, 1).Aggregate();
2347  }
2348 
2358  [global::__DynamicallyInvokable]
2359  public static float? Max(this ParallelQuery<float?> source)
2360  {
2361  if (source == null)
2362  {
2363  throw new ArgumentNullException("source");
2364  }
2365  return new NullableFloatMinMaxAggregationOperator(source, 1).Aggregate();
2366  }
2367 
2377  [global::__DynamicallyInvokable]
2378  public static double Max(this ParallelQuery<double> source)
2379  {
2380  if (source == null)
2381  {
2382  throw new ArgumentNullException("source");
2383  }
2384  return new DoubleMinMaxAggregationOperator(source, 1).Aggregate();
2385  }
2386 
2396  [global::__DynamicallyInvokable]
2397  public static double? Max(this ParallelQuery<double?> source)
2398  {
2399  if (source == null)
2400  {
2401  throw new ArgumentNullException("source");
2402  }
2403  return new NullableDoubleMinMaxAggregationOperator(source, 1).Aggregate();
2404  }
2405 
2415  [global::__DynamicallyInvokable]
2416  public static decimal Max(this ParallelQuery<decimal> source)
2417  {
2418  if (source == null)
2419  {
2420  throw new ArgumentNullException("source");
2421  }
2422  return new DecimalMinMaxAggregationOperator(source, 1).Aggregate();
2423  }
2424 
2434  [global::__DynamicallyInvokable]
2435  public static decimal? Max(this ParallelQuery<decimal?> source)
2436  {
2437  if (source == null)
2438  {
2439  throw new ArgumentNullException("source");
2440  }
2441  return new NullableDecimalMinMaxAggregationOperator(source, 1).Aggregate();
2442  }
2443 
2454  [global::__DynamicallyInvokable]
2455  public static TSource Max<TSource>(this ParallelQuery<TSource> source)
2456  {
2457  if (source == null)
2458  {
2459  throw new ArgumentNullException("source");
2460  }
2461  return AggregationMinMaxHelpers<TSource>.ReduceMax(source);
2462  }
2463 
2475  [global::__DynamicallyInvokable]
2476  public static int Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, int> selector)
2477  {
2478  return source.Select(selector).Max<int>();
2479  }
2480 
2492  [global::__DynamicallyInvokable]
2493  public static int? Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, int?> selector)
2494  {
2495  return source.Select(selector).Max<int?>();
2496  }
2497 
2509  [global::__DynamicallyInvokable]
2510  public static long Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, long> selector)
2511  {
2512  return source.Select(selector).Max<long>();
2513  }
2514 
2526  [global::__DynamicallyInvokable]
2527  public static long? Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, long?> selector)
2528  {
2529  return source.Select(selector).Max<long?>();
2530  }
2531 
2543  [global::__DynamicallyInvokable]
2544  public static float Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, float> selector)
2545  {
2546  return source.Select(selector).Max<float>();
2547  }
2548 
2560  [global::__DynamicallyInvokable]
2561  public static float? Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, float?> selector)
2562  {
2563  return source.Select(selector).Max<float?>();
2564  }
2565 
2577  [global::__DynamicallyInvokable]
2578  public static double Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, double> selector)
2579  {
2580  return source.Select(selector).Max<double>();
2581  }
2582 
2594  [global::__DynamicallyInvokable]
2595  public static double? Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, double?> selector)
2596  {
2597  return source.Select(selector).Max<double?>();
2598  }
2599 
2611  [global::__DynamicallyInvokable]
2612  public static decimal Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal> selector)
2613  {
2614  return source.Select(selector).Max<decimal>();
2615  }
2616 
2628  [global::__DynamicallyInvokable]
2629  public static decimal? Max<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal?> selector)
2630  {
2631  return source.Select(selector).Max<decimal?>();
2632  }
2633 
2646  [global::__DynamicallyInvokable]
2647  public static TResult Max<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
2648  {
2649  return source.Select(selector).Max();
2650  }
2651 
2661  [global::__DynamicallyInvokable]
2662  public static double Average(this ParallelQuery<int> source)
2663  {
2664  if (source == null)
2665  {
2666  throw new ArgumentNullException("source");
2667  }
2668  return new IntAverageAggregationOperator(source).Aggregate();
2669  }
2670 
2680  [global::__DynamicallyInvokable]
2681  public static double? Average(this ParallelQuery<int?> source)
2682  {
2683  if (source == null)
2684  {
2685  throw new ArgumentNullException("source");
2686  }
2687  return new NullableIntAverageAggregationOperator(source).Aggregate();
2688  }
2689 
2699  [global::__DynamicallyInvokable]
2700  public static double Average(this ParallelQuery<long> source)
2701  {
2702  if (source == null)
2703  {
2704  throw new ArgumentNullException("source");
2705  }
2706  return new LongAverageAggregationOperator(source).Aggregate();
2707  }
2708 
2718  [global::__DynamicallyInvokable]
2719  public static double? Average(this ParallelQuery<long?> source)
2720  {
2721  if (source == null)
2722  {
2723  throw new ArgumentNullException("source");
2724  }
2725  return new NullableLongAverageAggregationOperator(source).Aggregate();
2726  }
2727 
2737  [global::__DynamicallyInvokable]
2738  public static float Average(this ParallelQuery<float> source)
2739  {
2740  if (source == null)
2741  {
2742  throw new ArgumentNullException("source");
2743  }
2744  return new FloatAverageAggregationOperator(source).Aggregate();
2745  }
2746 
2756  [global::__DynamicallyInvokable]
2757  public static float? Average(this ParallelQuery<float?> source)
2758  {
2759  if (source == null)
2760  {
2761  throw new ArgumentNullException("source");
2762  }
2763  return new NullableFloatAverageAggregationOperator(source).Aggregate();
2764  }
2765 
2775  [global::__DynamicallyInvokable]
2776  public static double Average(this ParallelQuery<double> source)
2777  {
2778  if (source == null)
2779  {
2780  throw new ArgumentNullException("source");
2781  }
2782  return new DoubleAverageAggregationOperator(source).Aggregate();
2783  }
2784 
2793  [global::__DynamicallyInvokable]
2794  public static double? Average(this ParallelQuery<double?> source)
2795  {
2796  if (source == null)
2797  {
2798  throw new ArgumentNullException("source");
2799  }
2800  return new NullableDoubleAverageAggregationOperator(source).Aggregate();
2801  }
2802 
2812  [global::__DynamicallyInvokable]
2813  public static decimal Average(this ParallelQuery<decimal> source)
2814  {
2815  if (source == null)
2816  {
2817  throw new ArgumentNullException("source");
2818  }
2819  return new DecimalAverageAggregationOperator(source).Aggregate();
2820  }
2821 
2831  [global::__DynamicallyInvokable]
2832  public static decimal? Average(this ParallelQuery<decimal?> source)
2833  {
2834  if (source == null)
2835  {
2836  throw new ArgumentNullException("source");
2837  }
2838  return new NullableDecimalAverageAggregationOperator(source).Aggregate();
2839  }
2840 
2853  [global::__DynamicallyInvokable]
2854  public static double Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, int> selector)
2855  {
2856  return source.Select(selector).Average();
2857  }
2858 
2871  [global::__DynamicallyInvokable]
2872  public static double? Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, int?> selector)
2873  {
2874  return source.Select(selector).Average();
2875  }
2876 
2889  [global::__DynamicallyInvokable]
2890  public static double Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, long> selector)
2891  {
2892  return source.Select(selector).Average();
2893  }
2894 
2907  [global::__DynamicallyInvokable]
2908  public static double? Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, long?> selector)
2909  {
2910  return source.Select(selector).Average();
2911  }
2912 
2925  [global::__DynamicallyInvokable]
2926  public static float Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, float> selector)
2927  {
2928  return source.Select(selector).Average();
2929  }
2930 
2943  [global::__DynamicallyInvokable]
2944  public static float? Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, float?> selector)
2945  {
2946  return source.Select(selector).Average();
2947  }
2948 
2961  [global::__DynamicallyInvokable]
2962  public static double Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, double> selector)
2963  {
2964  return source.Select(selector).Average();
2965  }
2966 
2979  [global::__DynamicallyInvokable]
2980  public static double? Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, double?> selector)
2981  {
2982  return source.Select(selector).Average();
2983  }
2984 
2997  [global::__DynamicallyInvokable]
2998  public static decimal Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal> selector)
2999  {
3000  return source.Select(selector).Average();
3001  }
3002 
3015  [global::__DynamicallyInvokable]
3016  public static decimal? Average<TSource>(this ParallelQuery<TSource> source, Func<TSource, decimal?> selector)
3017  {
3018  return source.Select(selector).Average();
3019  }
3020 
3030  [global::__DynamicallyInvokable]
3031  public static bool Any<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
3032  {
3033  if (source == null)
3034  {
3035  throw new ArgumentNullException("source");
3036  }
3037  if (predicate == null)
3038  {
3039  throw new ArgumentNullException("predicate");
3040  }
3041  return new AnyAllSearchOperator<TSource>(source, qualification: true, predicate).Aggregate();
3042  }
3043 
3052  [global::__DynamicallyInvokable]
3053  public static bool Any<TSource>(this ParallelQuery<TSource> source)
3054  {
3055  if (source == null)
3056  {
3057  throw new ArgumentNullException("source");
3058  }
3059  return source.Any((TSource x) => true);
3060  }
3061 
3071  [global::__DynamicallyInvokable]
3072  public static bool All<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
3073  {
3074  if (source == null)
3075  {
3076  throw new ArgumentNullException("source");
3077  }
3078  if (predicate == null)
3079  {
3080  throw new ArgumentNullException("predicate");
3081  }
3082  return new AnyAllSearchOperator<TSource>(source, qualification: false, predicate).Aggregate();
3083  }
3084 
3094  [global::__DynamicallyInvokable]
3095  public static bool Contains<TSource>(this ParallelQuery<TSource> source, TSource value)
3096  {
3097  return source.Contains(value, null);
3098  }
3099 
3110  [global::__DynamicallyInvokable]
3111  public static bool Contains<TSource>(this ParallelQuery<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
3112  {
3113  if (source == null)
3114  {
3115  throw new ArgumentNullException("source");
3116  }
3117  return new ContainsSearchOperator<TSource>(source, value, comparer).Aggregate();
3118  }
3119 
3129  [global::__DynamicallyInvokable]
3130  public static ParallelQuery<TSource> Take<TSource>(this ParallelQuery<TSource> source, int count)
3131  {
3132  if (source == null)
3133  {
3134  throw new ArgumentNullException("source");
3135  }
3136  if (count > 0)
3137  {
3138  return new TakeOrSkipQueryOperator<TSource>(source, count, take: true);
3139  }
3140  return Empty<TSource>();
3141  }
3142 
3152  [global::__DynamicallyInvokable]
3153  public static ParallelQuery<TSource> TakeWhile<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
3154  {
3155  if (source == null)
3156  {
3157  throw new ArgumentNullException("source");
3158  }
3159  if (predicate == null)
3160  {
3161  throw new ArgumentNullException("predicate");
3162  }
3163  return new TakeOrSkipWhileQueryOperator<TSource>(source, predicate, null, take: true);
3164  }
3165 
3176  [global::__DynamicallyInvokable]
3177  public static ParallelQuery<TSource> TakeWhile<TSource>(this ParallelQuery<TSource> source, Func<TSource, int, bool> predicate)
3178  {
3179  if (source == null)
3180  {
3181  throw new ArgumentNullException("source");
3182  }
3183  if (predicate == null)
3184  {
3185  throw new ArgumentNullException("predicate");
3186  }
3187  return new TakeOrSkipWhileQueryOperator<TSource>(source, null, predicate, take: true);
3188  }
3189 
3200  [global::__DynamicallyInvokable]
3201  public static ParallelQuery<TSource> Skip<TSource>(this ParallelQuery<TSource> source, int count)
3202  {
3203  if (source == null)
3204  {
3205  throw new ArgumentNullException("source");
3206  }
3207  if (count <= 0)
3208  {
3209  return source;
3210  }
3211  return new TakeOrSkipQueryOperator<TSource>(source, count, take: false);
3212  }
3213 
3223  [global::__DynamicallyInvokable]
3224  public static ParallelQuery<TSource> SkipWhile<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
3225  {
3226  if (source == null)
3227  {
3228  throw new ArgumentNullException("source");
3229  }
3230  if (predicate == null)
3231  {
3232  throw new ArgumentNullException("predicate");
3233  }
3234  return new TakeOrSkipWhileQueryOperator<TSource>(source, predicate, null, take: false);
3235  }
3236 
3247  [global::__DynamicallyInvokable]
3248  public static ParallelQuery<TSource> SkipWhile<TSource>(this ParallelQuery<TSource> source, Func<TSource, int, bool> predicate)
3249  {
3250  if (source == null)
3251  {
3252  throw new ArgumentNullException("source");
3253  }
3254  if (predicate == null)
3255  {
3256  throw new ArgumentNullException("predicate");
3257  }
3258  return new TakeOrSkipWhileQueryOperator<TSource>(source, null, predicate, take: false);
3259  }
3260 
3268  [global::__DynamicallyInvokable]
3270  {
3271  if (first == null)
3272  {
3273  throw new ArgumentNullException("first");
3274  }
3275  if (second == null)
3276  {
3277  throw new ArgumentNullException("second");
3278  }
3279  return new ConcatQueryOperator<TSource>(first, second);
3280  }
3281 
3288  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3289  [global::__DynamicallyInvokable]
3291  {
3292  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3293  }
3294 
3304  [global::__DynamicallyInvokable]
3306  {
3307  if (first == null)
3308  {
3309  throw new ArgumentNullException("first");
3310  }
3311  if (second == null)
3312  {
3313  throw new ArgumentNullException("second");
3314  }
3315  return first.SequenceEqual(second, null);
3316  }
3317 
3324  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3325  [global::__DynamicallyInvokable]
3327  {
3328  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3329  }
3330 
3341  [global::__DynamicallyInvokable]
3343  {
3344  if (first == null)
3345  {
3346  throw new ArgumentNullException("first");
3347  }
3348  if (second == null)
3349  {
3350  throw new ArgumentNullException("second");
3351  }
3352  comparer = (comparer ?? EqualityComparer<TSource>.Default);
3353  QueryOperator<TSource> queryOperator = QueryOperator<TSource>.AsQueryOperator(first);
3354  QueryOperator<TSource> queryOperator2 = QueryOperator<TSource>.AsQueryOperator(second);
3355  QuerySettings querySettings = queryOperator.SpecifiedQuerySettings.Merge(queryOperator2.SpecifiedQuerySettings).WithDefaults().WithPerExecutionSettings(new CancellationTokenSource(), new System.Linq.Parallel.Shared<bool>(value: false));
3356  IEnumerator<TSource> enumerator = first.GetEnumerator();
3357  try
3358  {
3359  IEnumerator<TSource> enumerator2 = second.GetEnumerator();
3360  try
3361  {
3362  while (enumerator.MoveNext())
3363  {
3364  if (!enumerator2.MoveNext() || !comparer.Equals(enumerator.Current, enumerator2.Current))
3365  {
3366  return false;
3367  }
3368  }
3369  if (enumerator2.MoveNext())
3370  {
3371  return false;
3372  }
3373  }
3374  catch (ThreadAbortException)
3375  {
3376  throw;
3377  }
3378  catch (Exception ex2)
3379  {
3380  ExceptionAggregator.ThrowOCEorAggregateException(ex2, querySettings.CancellationState);
3381  }
3382  finally
3383  {
3384  DisposeEnumerator(enumerator2, querySettings.CancellationState);
3385  }
3386  }
3387  finally
3388  {
3389  DisposeEnumerator(enumerator, querySettings.CancellationState);
3390  }
3391  return true;
3392  }
3393 
3394  private static void DisposeEnumerator<TSource>(IEnumerator<TSource> e, CancellationState cancelState)
3395  {
3396  try
3397  {
3398  e.Dispose();
3399  }
3400  catch (ThreadAbortException)
3401  {
3402  throw;
3403  }
3404  catch (Exception ex2)
3405  {
3406  ExceptionAggregator.ThrowOCEorAggregateException(ex2, cancelState);
3407  }
3408  }
3409 
3417  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3418  [global::__DynamicallyInvokable]
3420  {
3421  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3422  }
3423 
3432  [global::__DynamicallyInvokable]
3434  {
3435  return source.Distinct(null);
3436  }
3437 
3446  [global::__DynamicallyInvokable]
3448  {
3449  if (source == null)
3450  {
3451  throw new ArgumentNullException("source");
3452  }
3453  return new DistinctQueryOperator<TSource>(source, comparer);
3454  }
3455 
3465  [global::__DynamicallyInvokable]
3467  {
3468  return first.Union(second, null);
3469  }
3470 
3479  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3480  [global::__DynamicallyInvokable]
3482  {
3483  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3484  }
3485 
3496  [global::__DynamicallyInvokable]
3498  {
3499  if (first == null)
3500  {
3501  throw new ArgumentNullException("first");
3502  }
3503  if (second == null)
3504  {
3505  throw new ArgumentNullException("second");
3506  }
3507  return new UnionQueryOperator<TSource>(first, second, comparer);
3508  }
3509 
3519  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3520  [global::__DynamicallyInvokable]
3522  {
3523  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3524  }
3525 
3535  [global::__DynamicallyInvokable]
3537  {
3538  return first.Intersect(second, null);
3539  }
3540 
3547  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3548  [global::__DynamicallyInvokable]
3550  {
3551  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3552  }
3553 
3564  [global::__DynamicallyInvokable]
3566  {
3567  if (first == null)
3568  {
3569  throw new ArgumentNullException("first");
3570  }
3571  if (second == null)
3572  {
3573  throw new ArgumentNullException("second");
3574  }
3575  return new IntersectQueryOperator<TSource>(first, second, comparer);
3576  }
3577 
3585  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3586  [global::__DynamicallyInvokable]
3588  {
3589  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3590  }
3591 
3601  [global::__DynamicallyInvokable]
3603  {
3604  return first.Except(second, null);
3605  }
3606 
3613  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3614  [global::__DynamicallyInvokable]
3616  {
3617  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3618  }
3619 
3631  [global::__DynamicallyInvokable]
3633  {
3634  if (first == null)
3635  {
3636  throw new ArgumentNullException("first");
3637  }
3638  if (second == null)
3639  {
3640  throw new ArgumentNullException("second");
3641  }
3642  return new ExceptQueryOperator<TSource>(first, second, comparer);
3643  }
3644 
3652  [Obsolete("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
3653  [global::__DynamicallyInvokable]
3655  {
3656  throw new NotSupportedException(SR.GetString("ParallelEnumerable_BinaryOpMustUseAsParallel"));
3657  }
3658 
3665  [global::__DynamicallyInvokable]
3667  {
3668  return source.AsSequential();
3669  }
3670 
3679  [global::__DynamicallyInvokable]
3680  public static TSource[] ToArray<TSource>(this ParallelQuery<TSource> source)
3681  {
3682  if (source == null)
3683  {
3684  throw new ArgumentNullException("source");
3685  }
3686  QueryOperator<TSource> queryOperator = source as QueryOperator<TSource>;
3687  if (queryOperator != null)
3688  {
3689  return queryOperator.ExecuteAndGetResultsAsArray();
3690  }
3691  return Enumerable.ToArray(source.ToList());
3692  }
3693 
3702  [global::__DynamicallyInvokable]
3704  {
3705  if (source == null)
3706  {
3707  throw new ArgumentNullException("source");
3708  }
3709  List<TSource> list = new List<TSource>();
3710  QueryOperator<TSource> queryOperator = source as QueryOperator<TSource>;
3711  IEnumerator<TSource> enumerator;
3712  if (queryOperator != null)
3713  {
3714  if (queryOperator.OrdinalIndexState == OrdinalIndexState.Indexible && queryOperator.OutputOrdered)
3715  {
3716  return new List<TSource>(source.ToArray());
3717  }
3718  enumerator = queryOperator.GetEnumerator(ParallelMergeOptions.FullyBuffered);
3719  }
3720  else
3721  {
3722  enumerator = source.GetEnumerator();
3723  }
3724  using (enumerator)
3725  {
3726  while (enumerator.MoveNext())
3727  {
3728  list.Add(enumerator.Current);
3729  }
3730  return list;
3731  }
3732  }
3733 
3745  [global::__DynamicallyInvokable]
3746  public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
3747  {
3748  return source.ToDictionary(keySelector, EqualityComparer<TKey>.Default);
3749  }
3750 
3763  [global::__DynamicallyInvokable]
3764  public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
3765  {
3766  if (source == null)
3767  {
3768  throw new ArgumentNullException("source");
3769  }
3770  if (keySelector == null)
3771  {
3772  throw new ArgumentNullException("keySelector");
3773  }
3774  Dictionary<TKey, TSource> dictionary = new Dictionary<TKey, TSource>(comparer);
3775  QueryOperator<TSource> queryOperator = source as QueryOperator<TSource>;
3776  IEnumerator<TSource> enumerator = (queryOperator == null) ? source.GetEnumerator() : queryOperator.GetEnumerator(ParallelMergeOptions.FullyBuffered, suppressOrderPreservation: true);
3777  using (enumerator)
3778  {
3779  while (enumerator.MoveNext())
3780  {
3781  TSource current = enumerator.Current;
3782  try
3783  {
3784  TKey key = keySelector(current);
3785  dictionary.Add(key, current);
3786  }
3787  catch (ThreadAbortException)
3788  {
3789  throw;
3790  }
3791  catch (Exception ex2)
3792  {
3793  throw new AggregateException(ex2);
3794  }
3795  }
3796  return dictionary;
3797  }
3798  }
3799 
3813  [global::__DynamicallyInvokable]
3814  public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
3815  {
3816  return source.ToDictionary(keySelector, elementSelector, EqualityComparer<TKey>.Default);
3817  }
3818 
3833  [global::__DynamicallyInvokable]
3834  public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
3835  {
3836  if (source == null)
3837  {
3838  throw new ArgumentNullException("source");
3839  }
3840  if (keySelector == null)
3841  {
3842  throw new ArgumentNullException("keySelector");
3843  }
3844  if (elementSelector == null)
3845  {
3846  throw new ArgumentNullException("elementSelector");
3847  }
3848  Dictionary<TKey, TElement> dictionary = new Dictionary<TKey, TElement>(comparer);
3849  QueryOperator<TSource> queryOperator = source as QueryOperator<TSource>;
3850  IEnumerator<TSource> enumerator = (queryOperator == null) ? source.GetEnumerator() : queryOperator.GetEnumerator(ParallelMergeOptions.FullyBuffered, suppressOrderPreservation: true);
3851  using (enumerator)
3852  {
3853  while (enumerator.MoveNext())
3854  {
3855  TSource current = enumerator.Current;
3856  try
3857  {
3858  dictionary.Add(keySelector(current), elementSelector(current));
3859  }
3860  catch (ThreadAbortException)
3861  {
3862  throw;
3863  }
3864  catch (Exception ex2)
3865  {
3866  throw new AggregateException(ex2);
3867  }
3868  }
3869  return dictionary;
3870  }
3871  }
3872 
3883  [global::__DynamicallyInvokable]
3884  public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector)
3885  {
3886  return source.ToLookup(keySelector, EqualityComparer<TKey>.Default);
3887  }
3888 
3900  [global::__DynamicallyInvokable]
3901  public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
3902  {
3903  if (source == null)
3904  {
3905  throw new ArgumentNullException("source");
3906  }
3907  if (keySelector == null)
3908  {
3909  throw new ArgumentNullException("keySelector");
3910  }
3911  comparer = (comparer ?? EqualityComparer<TKey>.Default);
3912  ParallelQuery<IGrouping<TKey, TSource>> parallelQuery = source.GroupBy(keySelector, comparer);
3913  System.Linq.Parallel.Lookup<TKey, TSource> lookup = new System.Linq.Parallel.Lookup<TKey, TSource>(comparer);
3914  QueryOperator<IGrouping<TKey, TSource>> queryOperator = parallelQuery as QueryOperator<IGrouping<TKey, TSource>>;
3915  IEnumerator<IGrouping<TKey, TSource>> enumerator = (queryOperator == null) ? parallelQuery.GetEnumerator() : queryOperator.GetEnumerator(ParallelMergeOptions.FullyBuffered);
3916  using (enumerator)
3917  {
3918  while (enumerator.MoveNext())
3919  {
3920  lookup.Add(enumerator.Current);
3921  }
3922  return lookup;
3923  }
3924  }
3925 
3938  [global::__DynamicallyInvokable]
3939  public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
3940  {
3941  return source.ToLookup(keySelector, elementSelector, EqualityComparer<TKey>.Default);
3942  }
3943 
3957  [global::__DynamicallyInvokable]
3958  public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
3959  {
3960  if (source == null)
3961  {
3962  throw new ArgumentNullException("source");
3963  }
3964  if (keySelector == null)
3965  {
3966  throw new ArgumentNullException("keySelector");
3967  }
3968  if (elementSelector == null)
3969  {
3970  throw new ArgumentNullException("elementSelector");
3971  }
3972  comparer = (comparer ?? EqualityComparer<TKey>.Default);
3973  ParallelQuery<IGrouping<TKey, TElement>> parallelQuery = source.GroupBy(keySelector, elementSelector, comparer);
3974  System.Linq.Parallel.Lookup<TKey, TElement> lookup = new System.Linq.Parallel.Lookup<TKey, TElement>(comparer);
3975  QueryOperator<IGrouping<TKey, TElement>> queryOperator = parallelQuery as QueryOperator<IGrouping<TKey, TElement>>;
3976  IEnumerator<IGrouping<TKey, TElement>> enumerator = (queryOperator == null) ? parallelQuery.GetEnumerator() : queryOperator.GetEnumerator(ParallelMergeOptions.FullyBuffered);
3977  using (enumerator)
3978  {
3979  while (enumerator.MoveNext())
3980  {
3981  lookup.Add(enumerator.Current);
3982  }
3983  return lookup;
3984  }
3985  }
3986 
3995  [global::__DynamicallyInvokable]
3997  {
3998  if (source == null)
3999  {
4000  throw new ArgumentNullException("source");
4001  }
4002  return new ReverseQueryOperator<TSource>(source);
4003  }
4004 
4013  [global::__DynamicallyInvokable]
4015  {
4016  if (source == null)
4017  {
4018  throw new ArgumentNullException("source");
4019  }
4020  return source.OfType<TResult>();
4021  }
4022 
4030  [global::__DynamicallyInvokable]
4032  {
4033  return source.Cast<TResult>();
4034  }
4035 
4036  private static TSource GetOneWithPossibleDefault<TSource>(QueryOperator<TSource> queryOp, bool throwIfTwo, bool defaultIfEmpty)
4037  {
4038  using (IEnumerator<TSource> enumerator = queryOp.GetEnumerator(ParallelMergeOptions.FullyBuffered))
4039  {
4040  if (enumerator.MoveNext())
4041  {
4042  TSource current = enumerator.Current;
4043  if (throwIfTwo && enumerator.MoveNext())
4044  {
4045  throw new InvalidOperationException(SR.GetString("MoreThanOneMatch"));
4046  }
4047  return current;
4048  }
4049  }
4050  if (defaultIfEmpty)
4051  {
4052  return default(TSource);
4053  }
4054  throw new InvalidOperationException(SR.GetString("NoElements"));
4055  }
4056 
4067  [global::__DynamicallyInvokable]
4068  public static TSource First<TSource>(this ParallelQuery<TSource> source)
4069  {
4070  if (source == null)
4071  {
4072  throw new ArgumentNullException("source");
4073  }
4074  FirstQueryOperator<TSource> firstQueryOperator = new FirstQueryOperator<TSource>(source, null);
4075  QuerySettings querySettings = firstQueryOperator.SpecifiedQuerySettings.WithDefaults();
4076  if (firstQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4077  {
4078  IEnumerable<TSource> source2 = firstQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4079  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4080  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).First();
4081  }
4082  return GetOneWithPossibleDefault(firstQueryOperator, throwIfTwo: false, defaultIfEmpty: false);
4083  }
4084 
4095  [global::__DynamicallyInvokable]
4096  public static TSource First<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4097  {
4098  if (source == null)
4099  {
4100  throw new ArgumentNullException("source");
4101  }
4102  if (predicate == null)
4103  {
4104  throw new ArgumentNullException("predicate");
4105  }
4106  FirstQueryOperator<TSource> firstQueryOperator = new FirstQueryOperator<TSource>(source, predicate);
4107  QuerySettings querySettings = firstQueryOperator.SpecifiedQuerySettings.WithDefaults();
4108  if (firstQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4109  {
4110  IEnumerable<TSource> source2 = firstQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4111  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4112  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).First(ExceptionAggregator.WrapFunc(predicate, querySettings.CancellationState));
4113  }
4114  return GetOneWithPossibleDefault(firstQueryOperator, throwIfTwo: false, defaultIfEmpty: false);
4115  }
4116 
4125  [global::__DynamicallyInvokable]
4126  public static TSource FirstOrDefault<TSource>(this ParallelQuery<TSource> source)
4127  {
4128  if (source == null)
4129  {
4130  throw new ArgumentNullException("source");
4131  }
4132  FirstQueryOperator<TSource> firstQueryOperator = new FirstQueryOperator<TSource>(source, null);
4133  QuerySettings querySettings = firstQueryOperator.SpecifiedQuerySettings.WithDefaults();
4134  if (firstQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4135  {
4136  IEnumerable<TSource> source2 = firstQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4137  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4138  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).FirstOrDefault();
4139  }
4140  return GetOneWithPossibleDefault(firstQueryOperator, throwIfTwo: false, defaultIfEmpty: true);
4141  }
4142 
4152  [global::__DynamicallyInvokable]
4153  public static TSource FirstOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4154  {
4155  if (source == null)
4156  {
4157  throw new ArgumentNullException("source");
4158  }
4159  if (predicate == null)
4160  {
4161  throw new ArgumentNullException("predicate");
4162  }
4163  FirstQueryOperator<TSource> firstQueryOperator = new FirstQueryOperator<TSource>(source, predicate);
4164  QuerySettings querySettings = firstQueryOperator.SpecifiedQuerySettings.WithDefaults();
4165  if (firstQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4166  {
4167  IEnumerable<TSource> source2 = firstQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4168  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4169  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).FirstOrDefault(ExceptionAggregator.WrapFunc(predicate, querySettings.CancellationState));
4170  }
4171  return GetOneWithPossibleDefault(firstQueryOperator, throwIfTwo: false, defaultIfEmpty: true);
4172  }
4173 
4184  [global::__DynamicallyInvokable]
4185  public static TSource Last<TSource>(this ParallelQuery<TSource> source)
4186  {
4187  if (source == null)
4188  {
4189  throw new ArgumentNullException("source");
4190  }
4191  LastQueryOperator<TSource> lastQueryOperator = new LastQueryOperator<TSource>(source, null);
4192  QuerySettings querySettings = lastQueryOperator.SpecifiedQuerySettings.WithDefaults();
4193  if (lastQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4194  {
4195  IEnumerable<TSource> source2 = lastQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4196  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4197  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).Last();
4198  }
4199  return GetOneWithPossibleDefault(lastQueryOperator, throwIfTwo: false, defaultIfEmpty: false);
4200  }
4201 
4212  [global::__DynamicallyInvokable]
4213  public static TSource Last<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4214  {
4215  if (source == null)
4216  {
4217  throw new ArgumentNullException("source");
4218  }
4219  if (predicate == null)
4220  {
4221  throw new ArgumentNullException("predicate");
4222  }
4223  LastQueryOperator<TSource> lastQueryOperator = new LastQueryOperator<TSource>(source, predicate);
4224  QuerySettings querySettings = lastQueryOperator.SpecifiedQuerySettings.WithDefaults();
4225  if (lastQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4226  {
4227  IEnumerable<TSource> source2 = lastQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4228  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4229  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).Last(ExceptionAggregator.WrapFunc(predicate, querySettings.CancellationState));
4230  }
4231  return GetOneWithPossibleDefault(lastQueryOperator, throwIfTwo: false, defaultIfEmpty: false);
4232  }
4233 
4242  [global::__DynamicallyInvokable]
4243  public static TSource LastOrDefault<TSource>(this ParallelQuery<TSource> source)
4244  {
4245  if (source == null)
4246  {
4247  throw new ArgumentNullException("source");
4248  }
4249  LastQueryOperator<TSource> lastQueryOperator = new LastQueryOperator<TSource>(source, null);
4250  QuerySettings querySettings = lastQueryOperator.SpecifiedQuerySettings.WithDefaults();
4251  if (lastQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4252  {
4253  IEnumerable<TSource> source2 = lastQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4254  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4255  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).LastOrDefault();
4256  }
4257  return GetOneWithPossibleDefault(lastQueryOperator, throwIfTwo: false, defaultIfEmpty: true);
4258  }
4259 
4269  [global::__DynamicallyInvokable]
4270  public static TSource LastOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4271  {
4272  if (source == null)
4273  {
4274  throw new ArgumentNullException("source");
4275  }
4276  if (predicate == null)
4277  {
4278  throw new ArgumentNullException("predicate");
4279  }
4280  LastQueryOperator<TSource> lastQueryOperator = new LastQueryOperator<TSource>(source, predicate);
4281  QuerySettings querySettings = lastQueryOperator.SpecifiedQuerySettings.WithDefaults();
4282  if (lastQueryOperator.LimitsParallelism && querySettings.ExecutionMode != ParallelExecutionMode.ForceParallelism)
4283  {
4284  IEnumerable<TSource> source2 = lastQueryOperator.Child.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
4285  IEnumerable<TSource> source3 = CancellableEnumerable.Wrap(source2, querySettings.CancellationState.ExternalCancellationToken);
4286  return ExceptionAggregator.WrapEnumerable(source3, querySettings.CancellationState).LastOrDefault(ExceptionAggregator.WrapFunc(predicate, querySettings.CancellationState));
4287  }
4288  return GetOneWithPossibleDefault(lastQueryOperator, throwIfTwo: false, defaultIfEmpty: true);
4289  }
4290 
4300  [global::__DynamicallyInvokable]
4301  public static TSource Single<TSource>(this ParallelQuery<TSource> source)
4302  {
4303  if (source == null)
4304  {
4305  throw new ArgumentNullException("source");
4306  }
4307  return GetOneWithPossibleDefault(new SingleQueryOperator<TSource>(source, null), throwIfTwo: true, defaultIfEmpty: false);
4308  }
4309 
4320  [global::__DynamicallyInvokable]
4321  public static TSource Single<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4322  {
4323  if (source == null)
4324  {
4325  throw new ArgumentNullException("source");
4326  }
4327  if (predicate == null)
4328  {
4329  throw new ArgumentNullException("predicate");
4330  }
4331  return GetOneWithPossibleDefault(new SingleQueryOperator<TSource>(source, predicate), throwIfTwo: true, defaultIfEmpty: false);
4332  }
4333 
4342  [global::__DynamicallyInvokable]
4343  public static TSource SingleOrDefault<TSource>(this ParallelQuery<TSource> source)
4344  {
4345  if (source == null)
4346  {
4347  throw new ArgumentNullException("source");
4348  }
4349  return GetOneWithPossibleDefault(new SingleQueryOperator<TSource>(source, null), throwIfTwo: true, defaultIfEmpty: true);
4350  }
4351 
4363  [global::__DynamicallyInvokable]
4364  public static TSource SingleOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
4365  {
4366  if (source == null)
4367  {
4368  throw new ArgumentNullException("source");
4369  }
4370  if (predicate == null)
4371  {
4372  throw new ArgumentNullException("predicate");
4373  }
4374  return GetOneWithPossibleDefault(new SingleQueryOperator<TSource>(source, predicate), throwIfTwo: true, defaultIfEmpty: true);
4375  }
4376 
4385  [global::__DynamicallyInvokable]
4387  {
4388  return source.DefaultIfEmpty(default(TSource));
4389  }
4390 
4400  [global::__DynamicallyInvokable]
4401  public static ParallelQuery<TSource> DefaultIfEmpty<TSource>(this ParallelQuery<TSource> source, TSource defaultValue)
4402  {
4403  if (source == null)
4404  {
4405  throw new ArgumentNullException("source");
4406  }
4407  return new DefaultIfEmptyQueryOperator<TSource>(source, defaultValue);
4408  }
4409 
4421  [global::__DynamicallyInvokable]
4422  public static TSource ElementAt<TSource>(this ParallelQuery<TSource> source, int index)
4423  {
4424  if (source == null)
4425  {
4426  throw new ArgumentNullException("source");
4427  }
4428  if (index < 0)
4429  {
4430  throw new ArgumentOutOfRangeException("index");
4431  }
4432  ElementAtQueryOperator<TSource> elementAtQueryOperator = new ElementAtQueryOperator<TSource>(source, index);
4433  if (elementAtQueryOperator.Aggregate(out TSource result, withDefaultValue: false))
4434  {
4435  return result;
4436  }
4437  throw new ArgumentOutOfRangeException("index");
4438  }
4439 
4449  [global::__DynamicallyInvokable]
4450  public static TSource ElementAtOrDefault<TSource>(this ParallelQuery<TSource> source, int index)
4451  {
4452  if (source == null)
4453  {
4454  throw new ArgumentNullException("source");
4455  }
4456  if (index >= 0)
4457  {
4458  ElementAtQueryOperator<TSource> elementAtQueryOperator = new ElementAtQueryOperator<TSource>(source, index);
4459  if (elementAtQueryOperator.Aggregate(out TSource result, withDefaultValue: true))
4460  {
4461  return result;
4462  }
4463  }
4464  return default(TSource);
4465  }
4466  }
4467 }
Provides a set of methods for querying objects that implement ParallelQuery{TSource}....
static TSource Aggregate< TSource >(this ParallelQuery< TSource > source, Func< TSource, TSource, TSource > func)
Applies in parallel an accumulator function over a sequence.
static decimal Sum(this ParallelQuery< decimal > source)
Computes in parallel the sum of a sequence of values.
static TSource Single< TSource >(this ParallelQuery< TSource > source)
Returns the only element of a parallel sequence, and throws an exception if there is not exactly one ...
static TSource FirstOrDefault< TSource >(this ParallelQuery< TSource > source)
Returns the first element of a parallel sequence, or a default value if the sequence contains no elem...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
static decimal Average(this ParallelQuery< decimal > source)
Computes in parallel the average of a sequence of values.
static double Average(this ParallelQuery< long > source)
Computes in parallel the average of a sequence of values.
Propagates notification that operations should be canceled.
bool MoveNext()
Advances the enumerator to the next element of the collection.
static IEnumerable< TSource > AsSequential< TSource >(this ParallelQuery< TSource > source)
Converts a T:System.Linq.ParallelQuery`1 into an T:System.Collections.Generic.IEnumerable`1 to force ...
static ? double Sum(this ParallelQuery< double?> source)
Computes in parallel the sum of a sequence of values.
static ParallelQuery< TSource > WithCancellation< TSource >(this ParallelQuery< TSource > source, CancellationToken cancellationToken)
Sets the T:System.Threading.CancellationToken to associate with the query.
static ? int Sum(this ParallelQuery< int?> source)
Computes in parallel the sum of a sequence of values.
static bool Contains< TSource >(this ParallelQuery< TSource > source, TSource value)
Determines in parallel whether a sequence contains a specified element by using the default equality ...
static float Max(this ParallelQuery< float > source)
Returns the maximum value in a parallel sequence of values.
static ParallelQuery< TSource > WithMergeOptions< TSource >(this ParallelQuery< TSource > source, ParallelMergeOptions mergeOptions)
Sets the merge options for this query, which specify how the query will buffer output.
static ParallelQuery< TSource > Where< TSource >(this ParallelQuery< TSource > source, Func< TSource, bool > predicate)
Filters in parallel a sequence of values based on a predicate.
static ? float Average(this ParallelQuery< float?> source)
Computes in parallel the average of a sequence of values.
static Dictionary< TKey, TElement > ToDictionary< TSource, TKey, TElement >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Creates a T:System.Collections.Generic.Dictionary`2 from a T:System.Linq.ParallelQuery`1 according to...
static ParallelQuery< TSource > AsOrdered< TSource >(this ParallelQuery< TSource > source)
Enables treatment of a data source as if it were ordered, overriding the default of unordered....
static ParallelQuery< TResult > SelectMany< TSource, TResult >(this ParallelQuery< TSource > source, Func< TSource, IEnumerable< TResult >> selector)
Projects in parallel each element of a sequence to an T:System.Collections.Generic....
static int Max(this ParallelQuery< int > source)
Returns the maximum value in a parallel sequence of values.
static TSource Max< TSource >(this ParallelQuery< TSource > source)
Returns the maximum value in a parallel sequence of values.
static decimal Max(this ParallelQuery< decimal > source)
Returns the maximum value in a parallel sequence of values.
static ? int Min(this ParallelQuery< int?> source)
Returns the minimum value in a parallel sequence of values.
static ParallelQuery AsParallel(this IEnumerable source)
Enables parallelization of a query.
static TSource Min< TSource >(this ParallelQuery< TSource > source)
Returns the minimum value in a parallel sequence of values.
static ILookup< TKey, TElement > ToLookup< TSource, TKey, TElement >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Creates an T:System.Linq.ILookup`2 from a T:System.Linq.ParallelQuery`1 according to specified key se...
static ParallelQuery< TResult > GroupBy< TSource, TKey, TElement, TResult >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector, Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Groups in parallel the elements of a sequence according to a specified key selector function and crea...
Represents an object that handles the low-level work of queuing tasks onto threads.
static ParallelQuery< TResult > Empty< TResult >()
Returns an empty ParallelQuery{TResult} that has the specified type argument.
static TSource First< TSource >(this ParallelQuery< TSource > source)
Returns the first element of a parallel sequence.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static ParallelQuery< TResult > Cast< TResult >(this ParallelQuery source)
Converts the elements of a ParallelQuery to the specified type.
static ? double Min(this ParallelQuery< double?> source)
Returns the minimum value in a parallel sequence of values.
Represents a callback delegate that has been registered with a T:System.Threading....
static ParallelQuery< TSource > WithExecutionMode< TSource >(this ParallelQuery< TSource > source, ParallelExecutionMode executionMode)
Sets the execution mode of the query.
static ? long Sum(this ParallelQuery< long?> source)
Computes in parallel the sum of a sequence of values.
static TResult Min< TSource, TResult >(this ParallelQuery< TSource > source, Func< TSource, TResult > selector)
Invokes in parallel a transform function on each element of a sequence and returns the minimum value.
static ? decimal Max(this ParallelQuery< decimal?> source)
Returns the maximum value in a parallel sequence of values.
static float Average(this ParallelQuery< float > source)
Computes in parallel the average of a sequence of values.
This is the default setting. PLINQ will examine the query's structure and will only parallelize the q...
static ? decimal Min(this ParallelQuery< decimal?> source)
Returns the minimum value in a parallel sequence of values.
static OrderedParallelQuery< TSource > OrderBy< TSource, TKey >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Sorts in parallel the elements of a sequence in ascending order according to a key.
static ParallelQuery< TResult > SelectMany< TSource, TCollection, TResult >(this ParallelQuery< TSource > source, Func< TSource, IEnumerable< TCollection >> collectionSelector, Func< TSource, TCollection, TResult > resultSelector)
Projects each element of a sequence to an T:System.Collections.Generic.IEnumerable`1,...
ParallelExecutionMode
The query execution mode is a hint that specifies how the system should handle performance trade-offs...
static double Max(this ParallelQuery< double > source)
Returns the maximum value in a parallel sequence of values.
static ? double Average(this ParallelQuery< int?> source)
Computes in parallel the average of a sequence of values.
static double Min(this ParallelQuery< double > source)
Returns the minimum value in a parallel sequence of values.
static ParallelQuery< TSource > Distinct< TSource >(this ParallelQuery< TSource > source)
Returns distinct elements from a parallel sequence by using the default equality comparer to compare ...
static ParallelQuery< TSource > AsParallel< TSource >(this IEnumerable< TSource > source)
Enables parallelization of a query.
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
static ParallelQuery< TResult > Zip< TFirst, TSecond, TResult >(this ParallelQuery< TFirst > first, ParallelQuery< TSecond > second, Func< TFirst, TSecond, TResult > resultSelector)
Merges in parallel two sequences by using the specified predicate function.
static ParallelQuery< TResult > Repeat< TResult >(TResult element, int count)
Generates a parallel sequence that contains one repeated value.
Represents one or more errors that occur during application execution.
static int Sum< TSource >(this ParallelQuery< TSource > source, Func< TSource, int > selector)
Computes in parallel the sum of the sequence of values that are obtained by invoking a transform func...
static ParallelQuery< TSource > Concat< TSource >(this ParallelQuery< TSource > first, ParallelQuery< TSource > second)
Concatenates two parallel sequences.
static TSource SingleOrDefault< TSource >(this ParallelQuery< TSource > source)
Returns the only element of a parallel sequence, or a default value if the sequence is empty; this me...
The exception that is thrown when an operation is performed on a disposed object.
static int Min(this ParallelQuery< int > source)
Returns the minimum value in a parallel sequence of values.
new bool Equals(object x, object y)
Determines whether the specified objects are equal.
static TResult Aggregate< TSource, TAccumulate, TResult >(this ParallelQuery< TSource > source, TAccumulate seed, Func< TAccumulate, TSource, TAccumulate > func, Func< TAccumulate, TResult > resultSelector)
Applies in parallel an accumulator function over a sequence. The specified seed value is used as the ...
static ? decimal Sum(this ParallelQuery< decimal?> source)
Computes in parallel the sum of a sequence of values.
static List< TSource > ToList< TSource >(this ParallelQuery< TSource > source)
Creates a T:System.Collections.Generic.List`1 from an T:System.Linq.ParallelQuery`1.
static ParallelQuery< TSource > Union< TSource >(this ParallelQuery< TSource > first, ParallelQuery< TSource > second)
Produces the set union of two parallel sequences by using the default equality comparer.
static ParallelQuery AsOrdered(this ParallelQuery source)
Enables treatment of a data source as if it were ordered, overriding the default of unordered....
static int Count< TSource >(this ParallelQuery< TSource > source)
Returns the number of elements in a parallel sequence.
static TSource LastOrDefault< TSource >(this ParallelQuery< TSource > source)
Returns the last element of a parallel sequence, or a default value if the sequence contains no eleme...
static OrderedParallelQuery< TSource > ThenBy< TSource, TKey >(this OrderedParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Performs in parallel a subsequent ordering of the elements in a sequence in ascending order according...
static OrderedParallelQuery< TSource > OrderByDescending< TSource, TKey >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Sorts in parallel the elements of a sequence in descending order according to a key.
static double Sum(this ParallelQuery< double > source)
Computes in parallel the sum of a sequence of values.
static ? float Max(this ParallelQuery< float?> source)
Returns the maximum value in a parallel sequence of values.
static double Average(this ParallelQuery< double > source)
Computes in parallel the average of a sequence of values.
static ParallelQuery< TResult > GroupBy< TSource, TKey, TResult >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector, Func< TKey, IEnumerable< TSource >, TResult > resultSelector)
Groups in parallel the elements of a sequence according to a specified key selector function and crea...
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
ParallelMergeOptions
Specifies the preferred type of output merge to use in a query. In other words, it indicates how PLIN...
static ? double Average(this ParallelQuery< double?> source)
Computes in parallel the average of a sequence of values.
static ? int Max(this ParallelQuery< int?> source)
Returns the maximum value in a parallel sequence of values.
static OrderedParallelQuery< TSource > ThenByDescending< TSource, TKey >(this OrderedParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Performs in parallel a subsequent ordering of the elements in a sequence in descending order,...
static ParallelQuery< TSource > Take< TSource >(this ParallelQuery< TSource > source, int count)
Returns a specified number of contiguous elements from the start of a parallel sequence.
static TSource [] ToArray< TSource >(this ParallelQuery< TSource > source)
Creates an array from a T:System.Linq.ParallelQuery`1.
static ? long Min(this ParallelQuery< long?> source)
Returns the minimum value in a parallel sequence of values.
Represents a sorted, parallel sequence.
static ? float Sum(this ParallelQuery< float?> source)
Computes in parallel the sum of a sequence of values.
static ? long Max(this ParallelQuery< long?> source)
Returns the maximum value in a parallel sequence of values.
static void ForAll< TSource >(this ParallelQuery< TSource > source, Action< TSource > action)
Invokes in parallel the specified action for each element in the source .
Defines an indexer, size property, and Boolean search method for data structures that map keys to T:S...
Definition: ILookup.cs:10
static ParallelQuery< int > Range(int start, int count)
Generates a parallel sequence of integral numbers within a specified range.
static long LongCount< TSource >(this ParallelQuery< TSource > source)
Returns an Int64 that represents the total number of elements in a parallel sequence.
static TAccumulate Aggregate< TSource, TAccumulate >(this ParallelQuery< TSource > source, TAccumulate seed, Func< TAccumulate, TSource, TAccumulate > func)
Applies in parallel an accumulator function over a sequence. The specified seed value is used as the ...
static float Min(this ParallelQuery< float > source)
Returns the minimum value in a parallel sequence of values.
Provides a set of static (Shared in Visual Basic) methods for querying objects that implement T:Syste...
Definition: Enumerable.cs:9
static TSource Last< TSource >(this ParallelQuery< TSource > source)
Returns the last element of a parallel sequence.
static bool SequenceEqual< TSource >(this ParallelQuery< TSource > first, ParallelQuery< TSource > second)
Determines whether two parallel sequences are equal by comparing the elements by using the default eq...
static bool All< TSource >(this ParallelQuery< TSource > source, Func< TSource, bool > predicate)
Determines in parallel whether all elements of a sequence satisfy a condition.
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
Definition: Dictionary.cs:17
static ParallelQuery< TSource > DefaultIfEmpty< TSource >(this ParallelQuery< TSource > source)
Returns the elements of the specified parallel sequence or the type parameter's default value in a si...
static ParallelQuery< TResult > Select< TSource, TResult >(this ParallelQuery< TSource > source, Func< TSource, TResult > selector)
Projects in parallel each element of a sequence into a new form.
The exception that is thrown when one of the arguments provided to a method is not valid.
static long Min(this ParallelQuery< long > source)
Returns the minimum value in a parallel sequence of values.
static ParallelQuery< TSource > Skip< TSource >(this ParallelQuery< TSource > source, int count)
Bypasses a specified number of elements in a parallel sequence and then returns the remaining element...
static decimal Min(this ParallelQuery< decimal > source)
Returns the minimum value in a parallel sequence of values.
static ParallelQuery< IGrouping< TKey, TSource > > GroupBy< TSource, TKey >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Groups in parallel the elements of a sequence according to a specified key selector function.
static ? float Min(this ParallelQuery< float?> source)
Returns the minimum value in a parallel sequence of values.
static int Sum(this ParallelQuery< int > source)
Computes in parallel the sum of a sequence of values.
static ? double Average(this ParallelQuery< long?> source)
Computes in parallel the average of a sequence of values.
static TSource ElementAt< TSource >(this ParallelQuery< TSource > source, int index)
Returns the element at a specified index in a parallel sequence.
static ParallelQuery< TSource > TakeWhile< TSource >(this ParallelQuery< TSource > source, Func< TSource, bool > predicate)
Returns elements from a parallel sequence as long as a specified condition is true.
static ParallelQuery< TResult > GroupJoin< TOuter, TInner, TKey, TResult >(this ParallelQuery< TOuter > outer, ParallelQuery< TInner > inner, Func< TOuter, TKey > outerKeySelector, Func< TInner, TKey > innerKeySelector, Func< TOuter, IEnumerable< TInner >, TResult > resultSelector)
Correlates in parallel the elements of two sequences based on equality of keys and groups the results...
static long Sum(this ParallelQuery< long > source)
Computes in parallel the sum of a sequence of values.
static ParallelQuery< TSource > SkipWhile< TSource >(this ParallelQuery< TSource > source, Func< TSource, bool > predicate)
Bypasses elements in a parallel sequence as long as a specified condition is true and then returns th...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
static ParallelQuery< TSource > WithDegreeOfParallelism< TSource >(this ParallelQuery< TSource > source, int degreeOfParallelism)
Sets the degree of parallelism to use in a query. Degree of parallelism is the maximum number of conc...
static Dictionary< TKey, TSource > ToDictionary< TSource, TKey >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Creates a T:System.Collections.Generic.Dictionary`2 from a T:System.Linq.ParallelQuery`1 according to...
Signals to a T:System.Threading.CancellationToken that it should be canceled.
static ParallelQuery< TSource > Intersect< TSource >(this ParallelQuery< TSource > first, ParallelQuery< TSource > second)
Produces the set intersection of two parallel sequences by using the default equality comparer to com...
static ParallelQuery< TSource > Except< TSource >(this ParallelQuery< TSource > first, ParallelQuery< TSource > second)
Produces the set difference of two parallel sequences by using the default equality comparer to compa...
The exception that is thrown when a method call is invalid for the object's current state.
static float Sum(this ParallelQuery< float > source)
Computes in parallel the sum of a sequence of values.
static double Average(this ParallelQuery< int > source)
Computes in parallel the average of a sequence of values.
static ILookup< TKey, TSource > ToLookup< TSource, TKey >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector)
Creates an T:System.Linq.ILookup`2 from a T:System.Linq.ParallelQuery`1 according to a specified key ...
static TSource ElementAtOrDefault< TSource >(this ParallelQuery< TSource > source, int index)
Returns the element at a specified index in a parallel sequence or a default value if the index is ou...
static ? decimal Average(this ParallelQuery< decimal?> source)
Computes in parallel the average of a sequence of values.
static long Max(this ParallelQuery< long > source)
Returns the maximum value in a parallel sequence of values.
static ? double Max(this ParallelQuery< double?> source)
Returns the maximum value in a parallel sequence of values.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
static ParallelQuery< TSource > Reverse< TSource >(this ParallelQuery< TSource > source)
Inverts the order of the elements in a parallel sequence.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
The exception that is thrown when a call is made to the M:System.Threading.Thread....
static double Average< TSource >(this ParallelQuery< TSource > source, Func< TSource, int > selector)
Computes in parallel the average of a sequence of values that are obtained by invoking a transform fu...
static bool Any< TSource >(this ParallelQuery< TSource > source, Func< TSource, bool > predicate)
Determines in parallel whether any element of a sequence satisfies a condition.
static ParallelQuery< TSource > AsUnordered< TSource >(this ParallelQuery< TSource > source)
Allows an intermediate query to be treated as if no ordering is implied among the elements.
static TResult Max< TSource, TResult >(this ParallelQuery< TSource > source, Func< TSource, TResult > selector)
Invokes in parallel a transform function on each element of a sequence and returns the maximum value.
Represents a particular manner of splitting a data source into multiple partitions.
Definition: Partitioner.cs:12
static ParallelQuery< TResult > OfType< TResult >(this ParallelQuery source)
Filters the elements of a ParallelQuery based on a specified type.
CancellationTokenRegistration Register(Action callback)
Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.
void Dispose()
Releases all resources used by the current instance of the T:System.Threading.CancellationTokenRegist...
static IEnumerable< TSource > AsEnumerable< TSource >(this ParallelQuery< TSource > source)
Converts a T:System.Linq.ParallelQuery`1 into an T:System.Collections.Generic.IEnumerable`1 to force ...
static ParallelQuery< IGrouping< TKey, TElement > > GroupBy< TSource, TKey, TElement >(this ParallelQuery< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Groups in parallel the elements of a sequence according to a specified key selector function and proj...
static ParallelQuery< TResult > Join< TOuter, TInner, TKey, TResult >(this ParallelQuery< TOuter > outer, ParallelQuery< TInner > inner, Func< TOuter, TKey > outerKeySelector, Func< TInner, TKey > innerKeySelector, Func< TOuter, TInner, TResult > resultSelector)
Correlates in parallel the elements of two sequences based on matching keys. The default equality com...