forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Queryable.cs
4167 lines (4009 loc) · 489 KB
/
Queryable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
namespace System.Linq
{
/// <summary>Provides a set of <see langword="static" /> (<see langword="Shared" /> in Visual Basic) methods for querying data structures that implement <see cref="System.Linq.IQueryable{T}" />.</summary>
/// <remarks>
/// <para>The set of methods declared in the <see cref="System.Linq.Queryable" /> class provides an implementation of the standard query operators for querying data sources that implement <see cref="System.Linq.IQueryable{T}" />. The standard query operators are general purpose methods that follow the LINQ pattern and enable you to express traversal, filter, and projection operations over data in any .NET-based programming language.</para>
/// <para>The majority of the methods in this class are defined as extension methods that extend the <see cref="System.Linq.IQueryable{T}" /> type. This means they can be called like an instance method on any object that implements <see cref="System.Linq.IQueryable{T}" />. These methods that extend <see cref="System.Linq.IQueryable{T}" /> do not perform any querying directly. Instead, their functionality is to build an <see cref="System.Linq.Expressions.Expression" /> object, which is an expression tree that represents the cumulative query. The methods then pass the new expression tree to either the <see cref="System.Linq.IQueryProvider.Execute{T}(System.Linq.Expressions.Expression)" /> method or the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the input <see cref="System.Linq.IQueryable{T}" />. The method that is called depends on whether the <see cref="System.Linq.Queryable" /> method returns a singleton value, in which case <see cref="System.Linq.IQueryProvider.Execute{T}(System.Linq.Expressions.Expression)" /> is called, or has enumerable results, in which case <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is called.</para>
/// <para>The actual query execution on the target data is performed by a class that implements <see cref="System.Linq.IQueryable{T}" />. The expectation of any <see cref="System.Linq.IQueryable{T}" /> implementation is that the result of executing an expression tree that was constructed by a <see cref="System.Linq.Queryable" /> standard query operator method is equivalent to the result of calling the corresponding method in the <see cref="System.Linq.Enumerable" /> class, if the data source were an <see cref="System.Collections.Generic.IEnumerable{T}" />.</para>
/// <para>In addition to the standard query operator methods that operate on <see cref="System.Linq.IQueryable{T}" /> objects, this class also contains a method, <see cref="O:System.Linq.Queryable.AsQueryable" />, which types <see cref="System.Collections.IEnumerable" /> objects as <see cref="System.Linq.IQueryable" /> objects.</para>
/// </remarks>
/// <related type="Article" href="https://msdn.microsoft.com/library/a73c4aec-5d15-4e98-b962-1274021ea93d">Language-Integrated Query (LINQ)</related>
/// <related type="Article" href="https://msdn.microsoft.com/library/24cda21e-8af8-4632-b519-c404a839b9b2">Standard Query Operators Overview</related>
/// <related type="Article" href="https://msdn.microsoft.com/library/fb1d3ed8-d5b0-4211-a71f-dd271529294b">Expression Trees</related>
/// <related type="Article" href="/dotnet/framework/data/adonet/sql/linq/">LINQ to SQL</related>
public static class Queryable
{
internal const string InMemoryQueryableExtensionMethodsRequiresUnreferencedCode = "Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.";
/// <summary>Converts a generic <see cref="System.Collections.Generic.IEnumerable{T}" /> to a generic <see cref="System.Linq.IQueryable{T}" />.</summary>
/// <typeparam name="TElement">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">A sequence to convert.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that represents the input sequence.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <remarks>If the type of <paramref name="source" /> implements <see cref="System.Linq.IQueryable{T}" />, <see cref="System.Linq.Queryable.AsQueryable{T}(System.Collections.Generic.IEnumerable{T})" /> returns it directly. Otherwise, it returns an <see cref="System.Linq.IQueryable{T}" /> that executes queries by calling the equivalent query operator methods in <see cref="System.Linq.Enumerable" /> instead of those in <see cref="System.Linq.Queryable" />.</remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.AsQueryable{T}(System.Collections.Generic.IEnumerable{T})" /> to convert an <see cref="System.Collections.Generic.IEnumerable{T}" /> to an <see cref="System.Linq.IQueryable{T}" />.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet125":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet125":::</example>
[RequiresUnreferencedCode(InMemoryQueryableExtensionMethodsRequiresUnreferencedCode)]
public static IQueryable<TElement> AsQueryable<TElement>(this IEnumerable<TElement> source)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source as IQueryable<TElement> ?? new EnumerableQuery<TElement>(source);
}
/// <summary>Converts an <see cref="System.Collections.IEnumerable" /> to an <see cref="System.Linq.IQueryable" />.</summary>
/// <param name="source">A sequence to convert.</param>
/// <returns>An <see cref="System.Linq.IQueryable" /> that represents the input sequence.</returns>
/// <exception cref="System.ArgumentException"><paramref name="source" /> does not implement <see cref="System.Collections.Generic.IEnumerable{T}" /> for some <see langword="T" />.</exception>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>If the type of <paramref name="source" /> implements <see cref="System.Linq.IQueryable{T}" />, <see cref="System.Linq.Queryable.AsQueryable(System.Collections.IEnumerable)" /> returns it directly. Otherwise, it returns an <see cref="System.Linq.IQueryable{T}" /> that executes queries by calling the equivalent query operator methods in <see cref="System.Linq.Enumerable" /> instead of those in <see cref="System.Linq.Queryable" />.</para>
/// <para>This method assumes that <paramref name="source" /> implements <see cref="System.Collections.Generic.IEnumerable{T}" /> for some `T`. At runtime, the result is of type <see cref="System.Linq.IQueryable{T}" /> for the same `T`. This method is useful in dynamic scenarios when you do not statically know the type of `T`.</para>
/// </remarks>
[RequiresUnreferencedCode(InMemoryQueryableExtensionMethodsRequiresUnreferencedCode)]
public static IQueryable AsQueryable(this IEnumerable source)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (source is IQueryable queryable) return queryable;
Type? enumType = TypeHelper.FindGenericType(typeof(IEnumerable<>), source.GetType());
if (enumType == null)
throw Error.ArgumentNotIEnumerableGeneric(nameof(source));
return EnumerableQuery.Create(enumType.GenericTypeArguments[0], source);
}
/// <summary>Filters a sequence of values based on a predicate.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> to filter.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from the input sequence that satisfy the condition specified by <paramref name="predicate" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it returns the elements from <paramref name="source" /> that satisfy the condition specified by <paramref name="predicate" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> to filter a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet110":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet110":::</example>
[DynamicDependency("Where`1", typeof(Enumerable))]
public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.Where_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Filters a sequence of values based on a predicate. Each element's index is used in the logic of the predicate function.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> to filter.</param>
/// <param name="predicate">A function to test each element for a condition; the second parameter of the function represents the index of the element in the source sequence.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from the input sequence that satisfy the condition specified by <paramref name="predicate" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it returns the elements from <paramref name="source" /> that satisfy the condition specified by <paramref name="predicate" />. The index of each source element is provided as the second argument to <paramref name="predicate" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Where{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> to filter a sequence based on a predicate that incorporates the index of each element.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet111":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet111":::</example>
[DynamicDependency("Where`1", typeof(Enumerable))]
public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.Where_Index_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Filters the elements of an <see cref="System.Linq.IQueryable" /> based on a specified type.</summary>
/// <typeparam name="TResult">The type to filter the elements of the sequence on.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable" /> whose elements to filter.</param>
/// <returns>A collection that contains the elements from <paramref name="source" /> that have type <typeparamref name="TResult" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>The `OfType` method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling `OfType` itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling `OfType` depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it filters out any elements in <paramref name="source" /> that are not of type <typeparamref name="TResult" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use `OfType` to filter out elements that are not of type <see cref="System.Reflection.PropertyInfo" /> from a list of elements of type <see cref="System.Reflection.MemberInfo" />.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet69":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet69":::</example>
[DynamicDependency("OfType`1", typeof(Enumerable))]
public static IQueryable<TResult> OfType<TResult>(this IQueryable source)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.OfType_TResult_1(typeof(TResult)), source.Expression));
}
/// <summary>Converts the elements of an <see cref="System.Linq.IQueryable" /> to the specified type.</summary>
/// <typeparam name="TResult">The type to convert the elements of <paramref name="source" /> to.</typeparam>
/// <param name="source">The <see cref="System.Linq.IQueryable" /> that contains the elements to be converted.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains each element of the source sequence converted to the specified type.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="System.InvalidCastException">An element in the sequence cannot be cast to type <typeparamref name="TResult" />.</exception>
/// <remarks>
/// <para>The <see cref="System.Linq.Queryable.Cast{T}(System.Linq.IQueryable)" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Cast{T}(System.Linq.IQueryable)" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Cast{T}(System.Linq.IQueryable)" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it converts the values in <paramref name="source" /> to type <typeparamref name="TResult" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Cast{T}(System.Linq.IQueryable)" /> to convert objects in a sequence to type <see cref="string" />.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet19":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet19":::</example>
[DynamicDependency("Cast`1", typeof(Enumerable))]
public static IQueryable<TResult> Cast<TResult>(this IQueryable source)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.Cast_TResult_1(typeof(TResult)), source.Expression));
}
/// <summary>Projects each element of a sequence into a new form.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TResult">The type of the value returned by the function represented by <paramref name="selector" />.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="selector">A projection function to apply to each element.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking a projection function on each element of <paramref name="source" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="selector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="selector" /> on each element of <paramref name="source" /> to project it into a different form.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> to project over a sequence of values.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet75":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet75":::</example>
[DynamicDependency("Select`2", typeof(Enumerable))]
public static IQueryable<TResult> Select<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (selector == null)
throw Error.ArgumentNull(nameof(selector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.Select_TSource_TResult_2(typeof(TSource), typeof(TResult)),
source.Expression, Expression.Quote(selector)
));
}
/// <summary>Projects each element of a sequence into a new form by incorporating the element's index.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TResult">The type of the value returned by the function represented by <paramref name="selector" />.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="selector">A projection function to apply to each element.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking a projection function on each element of <paramref name="source" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="selector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,T2}})" /> depend on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="selector" /> on each element of <paramref name="source" /> to project it into a different form.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Select{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,T2}})" /> to project over a sequence of values and use the index of each element in the projected form.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet76":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet76":::</example>
[DynamicDependency("Select`2", typeof(Enumerable))]
public static IQueryable<TResult> Select<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, int, TResult>> selector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (selector == null)
throw Error.ArgumentNull(nameof(selector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.Select_Index_TSource_TResult_2(typeof(TSource), typeof(TResult)),
source.Expression, Expression.Quote(selector)
));
}
/// <summary>Projects each element of a sequence to an <see cref="System.Collections.Generic.IEnumerable{T}" /> and combines the resulting sequences into one sequence.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TResult">The type of the elements of the sequence returned by the function represented by <paramref name="selector" />.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="selector">A projection function to apply to each element.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking a one-to-many projection function on each element of the input sequence.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="selector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="selector" /> on each element of <paramref name="source" /> to project it into an enumerable form. It then concatenates the enumerable results into a single, one-dimensional sequence.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}})" /> to perform a one-to-many projection over an array.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet77":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet77":::</example>
[DynamicDependency("SelectMany`2", typeof(Enumerable))]
public static IQueryable<TResult> SelectMany<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TResult>>> selector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (selector == null)
throw Error.ArgumentNull(nameof(selector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.SelectMany_TSource_TResult_2(typeof(TSource), typeof(TResult)),
source.Expression, Expression.Quote(selector)
));
}
/// <summary>Projects each element of a sequence to an <see cref="System.Collections.Generic.IEnumerable{T}" /> and combines the resulting sequences into one sequence. The index of each source element is used in the projected form of that element.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TResult">The type of the elements of the sequence returned by the function represented by <paramref name="selector" />.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="selector">A projection function to apply to each element; the second parameter of this function represents the index of the source element.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking a one-to-many projection function on each element of the input sequence.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="selector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="selector" /> on each element of <paramref name="source" /> to project it into an enumerable form. Each enumerable result incorporates the index of the source element. It then concatenates the enumerable results into a single, one-dimensional sequence.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.SelectMany{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}})" /> to perform a one-to-many projection over an array and use the index of each source element.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet78":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet78":::</example>
[DynamicDependency("SelectMany`2", typeof(Enumerable))]
public static IQueryable<TResult> SelectMany<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TResult>>> selector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (selector == null)
throw Error.ArgumentNull(nameof(selector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.SelectMany_Index_TSource_TResult_2(typeof(TSource), typeof(TResult)),
source.Expression, Expression.Quote(selector)
));
}
/// <summary>Projects each element of a sequence to an <see cref="System.Collections.Generic.IEnumerable{T}" /> that incorporates the index of the source element that produced it. A result selector function is invoked on each element of each intermediate sequence, and the resulting values are combined into a single, one-dimensional sequence and returned.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TCollection">The type of the intermediate elements collected by the function represented by <paramref name="collectionSelector" />.</typeparam>
/// <typeparam name="TResult">The type of the elements of the resulting sequence.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="collectionSelector">A projection function to apply to each element of the input sequence; the second parameter of this function represents the index of the source element.</param>
/// <param name="resultSelector">A projection function to apply to each element of each intermediate sequence.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking the one-to-many projection function <paramref name="collectionSelector" /> on each element of <paramref name="source" /> and then mapping each of those sequence elements and their corresponding <paramref name="source" /> element to a result element.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="collectionSelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,int,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="collectionSelector" /> on each element of <paramref name="source" /> to project it into an enumerable form. Each enumerable result incorporates the source element's index. Then the function represented by <paramref name="resultSelector" /> is invoked on each element in each intermediate sequence. The resulting values are concatenated into a single, one-dimensional sequence.</para>
/// </remarks>
[DynamicDependency("SelectMany`3", typeof(Enumerable))]
public static IQueryable<TResult> SelectMany<TSource, TCollection, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TCollection>>> collectionSelector, Expression<Func<TSource, TCollection, TResult>> resultSelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (collectionSelector == null)
throw Error.ArgumentNull(nameof(collectionSelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.SelectMany_Index_TSource_TCollection_TResult_3(typeof(TSource), typeof(TCollection), typeof(TResult)),
source.Expression, Expression.Quote(collectionSelector), Expression.Quote(resultSelector)
));
}
/// <summary>Projects each element of a sequence to an <see cref="System.Collections.Generic.IEnumerable{T}" /> and invokes a result selector function on each element therein. The resulting values from each intermediate sequence are combined into a single, one-dimensional sequence and returned.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TCollection">The type of the intermediate elements collected by the function represented by <paramref name="collectionSelector" />.</typeparam>
/// <typeparam name="TResult">The type of the elements of the resulting sequence.</typeparam>
/// <param name="source">A sequence of values to project.</param>
/// <param name="collectionSelector">A projection function to apply to each element of the input sequence.</param>
/// <param name="resultSelector">A projection function to apply to each element of each intermediate sequence.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> whose elements are the result of invoking the one-to-many projection function <paramref name="collectionSelector" /> on each element of <paramref name="source" /> and then mapping each of those sequence elements and their corresponding <paramref name="source" /> element to a result element.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="collectionSelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it invokes <paramref name="collectionSelector" /> on each element of <paramref name="source" /> to project it into an enumerable form. Then the function represented by <paramref name="resultSelector" /> is invoked on each element in each intermediate sequence. The resulting values are concatenated into a single, one-dimensional sequence.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.SelectMany{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2}}},System.Linq.Expressions.Expression{System.Func{T1,T2,T3}})" /> to perform a one-to-many projection over an array. This example uses a result selector function to keep the source element that corresponds to each intermediate sequence in scope for the final call to `Select`.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet124":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet124":::</example>
[DynamicDependency("SelectMany`3", typeof(Enumerable))]
public static IQueryable<TResult> SelectMany<TSource, TCollection, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TCollection>>> collectionSelector, Expression<Func<TSource, TCollection, TResult>> resultSelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (collectionSelector == null)
throw Error.ArgumentNull(nameof(collectionSelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return source.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.SelectMany_TSource_TCollection_TResult_3(typeof(TSource), typeof(TCollection), typeof(TResult)),
source.Expression, Expression.Quote(collectionSelector), Expression.Quote(resultSelector)
));
}
private static Expression GetSourceExpression<TSource>(IEnumerable<TSource> source)
{
IQueryable<TSource>? q = source as IQueryable<TSource>;
return q != null ? q.Expression : Expression.Constant(source, typeof(IEnumerable<TSource>));
}
/// <summary>Correlates the elements of two sequences based on matching keys. The default equality comparer is used to compare keys.</summary>
/// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
/// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
/// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
/// <typeparam name="TResult">The type of the result elements.</typeparam>
/// <param name="outer">The first sequence to join.</param>
/// <param name="inner">The sequence to join to the first sequence.</param>
/// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
/// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
/// <param name="resultSelector">A function to create a result element from two matching elements.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that has elements of type <typeparamref name="TResult" /> obtained by performing an inner join on two sequences.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="outer" /> or <paramref name="inner" /> or <paramref name="outerKeySelector" /> or <paramref name="innerKeySelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="outer" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}})" /> depends on the implementation of the type of the <paramref name="outer" /> parameter. The expected behavior is that of an inner join. The <paramref name="outerKeySelector" /> and <paramref name="innerKeySelector" /> functions are used to extract keys from <paramref name="outer" /> and <paramref name="inner" />, respectively. These keys are compared for equality to match elements from each sequence. A pair of elements is stored for each element in <paramref name="inner" /> that matches an element in <paramref name="outer" />. Then the <paramref name="resultSelector" /> function is invoked to project a result object from each pair of matching elements.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}})" /> to perform an inner join of two sequences based on a common key.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet42":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet42":::</example>
[DynamicDependency("Join`4", typeof(Enumerable))]
public static IQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector)
{
if (outer == null)
throw Error.ArgumentNull(nameof(outer));
if (inner == null)
throw Error.ArgumentNull(nameof(inner));
if (outerKeySelector == null)
throw Error.ArgumentNull(nameof(outerKeySelector));
if (innerKeySelector == null)
throw Error.ArgumentNull(nameof(innerKeySelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return outer.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.Join_TOuter_TInner_TKey_TResult_5(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), outer.Expression, GetSourceExpression(inner), Expression.Quote(outerKeySelector), Expression.Quote(innerKeySelector), Expression.Quote(resultSelector)));
}
/// <summary>Correlates the elements of two sequences based on matching keys. A specified <see cref="System.Collections.Generic.IEqualityComparer{T}" /> is used to compare keys.</summary>
/// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
/// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
/// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
/// <typeparam name="TResult">The type of the result elements.</typeparam>
/// <param name="outer">The first sequence to join.</param>
/// <param name="inner">The sequence to join to the first sequence.</param>
/// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
/// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
/// <param name="resultSelector">A function to create a result element from two matching elements.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IEqualityComparer{T}" /> to hash and compare keys.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that has elements of type <typeparamref name="TResult" /> obtained by performing an inner join on two sequences.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="outer" /> or <paramref name="inner" /> or <paramref name="outerKeySelector" /> or <paramref name="innerKeySelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}},System.Collections.Generic.IEqualityComparer{T3})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}},System.Collections.Generic.IEqualityComparer{T3})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="outer" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Join{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,T2,T4}},System.Collections.Generic.IEqualityComparer{T3})" /> depends on the implementation of the type of the <paramref name="outer" /> parameter. The expected behavior is that of an inner join. The <paramref name="outerKeySelector" /> and <paramref name="innerKeySelector" /> functions are used to extract keys from <paramref name="outer" /> and <paramref name="inner" />, respectively. These keys are compared for equality by using <paramref name="comparer" />. The outcome of the comparisons is used to create a matching pair for each element in <paramref name="inner" /> that matches an element in <paramref name="outer" />. Then the <paramref name="resultSelector" /> function is invoked to project a result object from each pair of matching elements.</para>
/// </remarks>
[DynamicDependency("Join`4", typeof(Enumerable))]
public static IQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
{
if (outer == null)
throw Error.ArgumentNull(nameof(outer));
if (inner == null)
throw Error.ArgumentNull(nameof(inner));
if (outerKeySelector == null)
throw Error.ArgumentNull(nameof(outerKeySelector));
if (innerKeySelector == null)
throw Error.ArgumentNull(nameof(innerKeySelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return outer.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.Join_TOuter_TInner_TKey_TResult_6(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), outer.Expression, GetSourceExpression(inner), Expression.Quote(outerKeySelector), Expression.Quote(innerKeySelector), Expression.Quote(resultSelector), Expression.Constant(comparer, typeof(IEqualityComparer<TKey>))));
}
/// <summary>Correlates the elements of two sequences based on key equality and groups the results. The default equality comparer is used to compare keys.</summary>
/// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
/// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
/// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
/// <typeparam name="TResult">The type of the result elements.</typeparam>
/// <param name="outer">The first sequence to join.</param>
/// <param name="inner">The sequence to join to the first sequence.</param>
/// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
/// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
/// <param name="resultSelector">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements of type <typeparamref name="TResult" /> obtained by performing a grouped join on two sequences.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="outer" /> or <paramref name="inner" /> or <paramref name="outerKeySelector" /> or <paramref name="innerKeySelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="outer" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}})" /> depends on the implementation of the type of the <paramref name="outer" /> parameter. The expected behavior is that the <paramref name="outerKeySelector" /> and <paramref name="innerKeySelector" /> functions are used to extract keys from <paramref name="outer" /> and <paramref name="inner" />, respectively. These keys are compared for equality to match each element in <paramref name="outer" /> with zero or more elements from <paramref name="inner" />. Then the <paramref name="resultSelector" /> function is invoked to project a result object from each group of correlated elements.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}})" /> to perform a grouped join on two sequences.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet40":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet40":::</example>
[DynamicDependency("GroupJoin`4", typeof(Enumerable))]
public static IQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector)
{
if (outer == null)
throw Error.ArgumentNull(nameof(outer));
if (inner == null)
throw Error.ArgumentNull(nameof(inner));
if (outerKeySelector == null)
throw Error.ArgumentNull(nameof(outerKeySelector));
if (innerKeySelector == null)
throw Error.ArgumentNull(nameof(innerKeySelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return outer.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.GroupJoin_TOuter_TInner_TKey_TResult_5(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), outer.Expression, GetSourceExpression(inner), Expression.Quote(outerKeySelector), Expression.Quote(innerKeySelector), Expression.Quote(resultSelector)));
}
/// <summary>Correlates the elements of two sequences based on key equality and groups the results. A specified <see cref="System.Collections.Generic.IEqualityComparer{T}" /> is used to compare keys.</summary>
/// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
/// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
/// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
/// <typeparam name="TResult">The type of the result elements.</typeparam>
/// <param name="outer">The first sequence to join.</param>
/// <param name="inner">The sequence to join to the first sequence.</param>
/// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
/// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
/// <param name="resultSelector">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
/// <param name="comparer">A comparer to hash and compare keys.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements of type <typeparamref name="TResult" /> obtained by performing a grouped join on two sequences.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="outer" /> or <paramref name="inner" /> or <paramref name="outerKeySelector" /> or <paramref name="innerKeySelector" /> or <paramref name="resultSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}},System.Collections.Generic.IEqualityComparer{T3})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}},System.Collections.Generic.IEqualityComparer{T3})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="outer" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.GroupJoin{T1,T2,T3,T4}(System.Linq.IQueryable{T1},System.Collections.Generic.IEnumerable{T2},System.Linq.Expressions.Expression{System.Func{T1,T3}},System.Linq.Expressions.Expression{System.Func{T2,T3}},System.Linq.Expressions.Expression{System.Func{T1,System.Collections.Generic.IEnumerable{T2},T4}},System.Collections.Generic.IEqualityComparer{T3})" /> depends on the implementation of the type of the <paramref name="outer" /> parameter. The expected behavior is that the <paramref name="outerKeySelector" /> and <paramref name="innerKeySelector" /> functions are used to extract keys from <paramref name="outer" /> and <paramref name="inner" />, respectively. These keys are compared for equality by using <paramref name="comparer" />. The outcome of the comparisons is used to match each element in <paramref name="outer" /> with zero or more elements from <paramref name="inner" />. Then the <paramref name="resultSelector" /> function is invoked to project a result object from each group of correlated elements.</para>
/// </remarks>
[DynamicDependency("GroupJoin`4", typeof(Enumerable))]
public static IQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
{
if (outer == null)
throw Error.ArgumentNull(nameof(outer));
if (inner == null)
throw Error.ArgumentNull(nameof(inner));
if (outerKeySelector == null)
throw Error.ArgumentNull(nameof(outerKeySelector));
if (innerKeySelector == null)
throw Error.ArgumentNull(nameof(innerKeySelector));
if (resultSelector == null)
throw Error.ArgumentNull(nameof(resultSelector));
return outer.Provider.CreateQuery<TResult>(
Expression.Call(
null,
CachedReflectionInfo.GroupJoin_TOuter_TInner_TKey_TResult_6(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), outer.Expression, GetSourceExpression(inner), Expression.Quote(outerKeySelector), Expression.Quote(innerKeySelector), Expression.Quote(resultSelector), Expression.Constant(comparer, typeof(IEqualityComparer<TKey>))));
}
/// <summary>Sorts the elements of a sequence in ascending order according to a key.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function that is represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">A sequence of values to order.</param>
/// <param name="keySelector">A function to extract a key from an element.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it sorts the elements of <paramref name="source" /> based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> to sort the elements of a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet70":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet70":::</example>
[DynamicDependency("OrderBy`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.OrderBy_TSource_TKey_2(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector)
));
}
/// <summary>Sorts the elements of a sequence in ascending order by using a specified comparer.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function that is represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">A sequence of values to order.</param>
/// <param name="keySelector">A function to extract a key from an element.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IComparer{T}" /> to compare keys.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> or <paramref name="comparer" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.OrderBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it sorts the elements of <paramref name="source" /> based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. The <paramref name="comparer" /> parameter is used to compare keys.</para>
/// </remarks>
[DynamicDependency("OrderBy`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.OrderBy_TSource_TKey_3(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer<TKey>))
));
}
/// <summary>Sorts the elements of a sequence in descending order according to a key.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function that is represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">A sequence of values to order.</param>
/// <param name="keySelector">A function to extract a key from an element.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted in descending order according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it sorts the elements of <paramref name="source" /> in descending order, based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />.</para>
/// </remarks>
[DynamicDependency("OrderByDescending`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.OrderByDescending_TSource_TKey_2(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector)
));
}
/// <summary>Sorts the elements of a sequence in descending order by using a specified comparer.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function that is represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">A sequence of values to order.</param>
/// <param name="keySelector">A function to extract a key from an element.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IComparer{T}" /> to compare keys.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted in descending order according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> or <paramref name="comparer" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it sorts the elements of <paramref name="source" /> in descending order, based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. The <paramref name="comparer" /> parameter is used to compare keys.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.OrderByDescending{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> to sort the elements of a sequence in descending order by using a custom comparer.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet71":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet71":::</example>
[DynamicDependency("OrderByDescending`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.OrderByDescending_TSource_TKey_3(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer<TKey>))
));
}
/// <summary>Performs a subsequent ordering of the elements in a sequence in ascending order according to a key.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IOrderedQueryable{T}" /> that contains elements to sort.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it performs a secondary sort of the elements of <paramref name="source" /> based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. All previously established sort orders are preserved.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> to perform a secondary ordering of the elements in a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet102":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet102":::</example>
[DynamicDependency("ThenBy`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.ThenBy_TSource_TKey_2(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector)
));
}
/// <summary>Performs a subsequent ordering of the elements in a sequence in ascending order by using a specified comparer.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IOrderedQueryable{T}" /> that contains elements to sort.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IComparer{T}" /> to compare keys.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> or <paramref name="comparer" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it performs a secondary sort of the elements of <paramref name="source" /> based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. All previously established sort orders are preserved. The <paramref name="comparer" /> parameter is used to compare key values.</para>
/// </remarks>
[DynamicDependency("ThenBy`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.ThenBy_TSource_TKey_3(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer<TKey>))
));
}
/// <summary>Performs a subsequent ordering of the elements in a sequence in descending order, according to a key.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented by <paramref name="keySelector" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IOrderedQueryable{T}" /> that contains elements to sort.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <returns>An <see cref="System.Linq.IOrderedQueryable{T}" /> whose elements are sorted in descending order according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.ThenByDescending{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.ThenByDescending{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.ThenByDescending{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it performs a secondary sort of the elements of <paramref name="source" /> in descending order, based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. All previously established sort orders are preserved.</para>
/// </remarks>
[DynamicDependency("ThenByDescending`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.ThenByDescending_TSource_TKey_2(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector)
));
}
/// <summary>Performs a subsequent ordering of the elements in a sequence in descending order by using a specified comparer.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key that is returned by the <paramref name="keySelector" /> function.</typeparam>
/// <param name="source">An <see cref="System.Linq.IOrderedQueryable{T}" /> that contains elements to sort.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IComparer{T}" /> to compare keys.</param>
/// <returns>A collection whose elements are sorted in descending order according to a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> or <paramref name="comparer" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter. The result of calling <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> is cast to type <see cref="System.Linq.IOrderedQueryable{T}" /> and returned.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.ThenBy{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it performs a secondary sort of the elements of <paramref name="source" /> in descending order, based on the key obtained by invoking <paramref name="keySelector" /> on each element of <paramref name="source" />. All previously established sort orders are preserved. The <paramref name="comparer" /> parameter is used to compare key values.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.ThenByDescending{T1,T2}(System.Linq.IOrderedQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Collections.Generic.IComparer{T2})" /> to perform a secondary ordering of the elements in a sequence in descending order by using a custom comparer.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet103":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet103":::</example>
[DynamicDependency("ThenByDescending`2", typeof(Enumerable))]
public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return (IOrderedQueryable<TSource>)source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.ThenByDescending_TSource_TKey_3(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer<TKey>))
));
}
/// <summary>Returns a specified number of contiguous elements from the start of a sequence.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">The sequence to return elements from.</param>
/// <param name="count">The number of elements to return.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains the specified number of elements from the start of <paramref name="source" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>The <see cref="System.Linq.Queryable.Take{T}(System.Linq.IQueryable{T},int)" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Take{T}(System.Linq.IQueryable{T},int)" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Take{T}(System.Linq.IQueryable{T},int)" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it takes the first <paramref name="count" /> elements from the start of <paramref name="source" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Take{T}(System.Linq.IQueryable{T},int)" /> to return elements from the start of a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet99":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet99":::</example>
[DynamicDependency("Take`1", typeof(Enumerable))]
public static IQueryable<TSource> Take<TSource>(this IQueryable<TSource> source, int count)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.Take_Int32_TSource_2(typeof(TSource)),
source.Expression, Expression.Constant(count)
));
}
/// <summary>Returns a specified range of contiguous elements from a sequence.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">The sequence to return elements from.</param>
/// <param name="range">The range of elements to return, which has start and end indexes either from the start or the end.</param>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <returns>An <see cref="IQueryable{T}" /> that contains the specified <paramref name="range" /> of elements from the <paramref name="source" /> sequence.</returns>
[DynamicDependency("Take`1", typeof(Enumerable))]
public static IQueryable<TSource> Take<TSource>(this IQueryable<TSource> source, Range range)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.Take_Range_TSource_2(typeof(TSource)),
source.Expression, Expression.Constant(range)
));
}
/// <summary>Returns elements from a sequence as long as a specified condition is true.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">The sequence to return elements from.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from the input sequence occurring before the element at which the test specified by <paramref name="predicate" /> no longer passes.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it applies <paramref name="predicate" /> to each element in <paramref name="source" /> until it finds an element for which <paramref name="predicate" /> returns <see langword="false" />. It returns all the elements up until that point.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> to return elements from the start of a sequence as long as a condition is true.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet100":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet100":::</example>
[DynamicDependency("TakeWhile`1", typeof(Enumerable))]
public static IQueryable<TSource> TakeWhile<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.TakeWhile_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Returns elements from a sequence as long as a specified condition is true. The element's index is used in the logic of the predicate function.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">The sequence to return elements from.</param>
/// <param name="predicate">A function to test each element for a condition; the second parameter of the function represents the index of the element in the source sequence.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from the input sequence occurring before the element at which the test specified by <paramref name="predicate" /> no longer passes.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it applies <paramref name="predicate" /> to each element in <paramref name="source" /> until it finds an element for which <paramref name="predicate" /> returns <see langword="false" />. It returns all the elements up until that point. The index of each source element is provided as the second argument to <paramref name="predicate" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.TakeWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> to return elements from the start of a sequence as long as a condition that uses the index of the element is true.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet101":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet101":::</example>
[DynamicDependency("TakeWhile`1", typeof(Enumerable))]
public static IQueryable<TSource> TakeWhile<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.TakeWhile_Index_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Bypasses a specified number of elements in a sequence and then returns the remaining elements.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> to return elements from.</param>
/// <param name="count">The number of elements to skip before returning the remaining elements.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements that occur after the specified index in the input sequence.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>The <see cref="System.Linq.Queryable.Skip{T}(System.Linq.IQueryable{T},int)" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.Skip{T}(System.Linq.IQueryable{T},int)" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.Skip{T}(System.Linq.IQueryable{T},int)" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it skips the first <paramref name="count" /> elements in <paramref name="source" /> and returns the remaining elements.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.Skip{T}(System.Linq.IQueryable{T},int)" /> to skip a specified number of elements in a sorted array and return the remaining elements.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet87":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet87":::</example>
[DynamicDependency("Skip`1", typeof(Enumerable))]
public static IQueryable<TSource> Skip<TSource>(this IQueryable<TSource> source, int count)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.Skip_TSource_2(typeof(TSource)),
source.Expression, Expression.Constant(count)
));
}
/// <summary>Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> to return elements from.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from <paramref name="source" /> starting at the first element in the linear series that does not pass the test specified by <paramref name="predicate" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it applies <paramref name="predicate" /> to each element in <paramref name="source" /> until it finds an element for which <paramref name="predicate" /> returns false. That element and all the remaining elements are returned.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,bool}})" /> to skip elements of an array as long as a condition is true.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet88":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet88":::</example>
[DynamicDependency("SkipWhile`1", typeof(Enumerable))]
public static IQueryable<TSource> SkipWhile<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.SkipWhile_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. The element's index is used in the logic of the predicate function.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> to return elements from.</param>
/// <param name="predicate">A function to test each element for a condition; the second parameter of this function represents the index of the source element.</param>
/// <returns>An <see cref="System.Linq.IQueryable{T}" /> that contains elements from <paramref name="source" /> starting at the first element in the linear series that does not pass the test specified by <paramref name="predicate" />.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it applies <paramref name="predicate" /> to each element in <paramref name="source" /> until it finds an element for which <paramref name="predicate" /> returns false. That element and all the remaining elements are returned. The index of each source element is provided as the second argument to <paramref name="predicate" />.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.SkipWhile{T}(System.Linq.IQueryable{T},System.Linq.Expressions.Expression{System.Func{T,int,bool}})" /> to skip elements of an array as long as a condition that depends on the element's index is true.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" interactive="try-dotnet-method" id="Snippet89":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet89":::</example>
[DynamicDependency("SkipWhile`1", typeof(Enumerable))]
public static IQueryable<TSource> SkipWhile<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
CachedReflectionInfo.SkipWhile_Index_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
}
/// <summary>Groups the elements of a sequence according to a specified key selector function.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented in <paramref name="keySelector" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> whose elements to group.</param>
/// <param name="keySelector">A function to extract the key for each element.</param>
/// <returns>An <c>IQueryable<IGrouping<TKey, TSource>></c> in C# or <c>IQueryable(Of IGrouping(Of TKey, TSource))</c> in Visual Basic where each <see cref="System.Linq.IGrouping{T1,T2}" /> object contains a sequence of objects and a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.GroupBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.GroupBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.GroupBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it groups the elements of <paramref name="source" /> by a key value that is obtained by invoking <paramref name="keySelector" /> on each element.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.GroupBy{T1,T2}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}})" /> to group the elements of a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet14":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet14":::</example>
[DynamicDependency("GroupBy`2", typeof(Enumerable))]
public static IQueryable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
return source.Provider.CreateQuery<IGrouping<TKey, TSource>>(
Expression.Call(
null,
CachedReflectionInfo.GroupBy_TSource_TKey_2(typeof(TSource), typeof(TKey)),
source.Expression, Expression.Quote(keySelector)
));
}
/// <summary>Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented in <paramref name="keySelector" />.</typeparam>
/// <typeparam name="TElement">The type of the elements in each <see cref="System.Linq.IGrouping{T1,T2}" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> whose elements to group.</param>
/// <param name="keySelector">A function to extract the key for each element.</param>
/// <param name="elementSelector">A function to map each source element to an element in an <see cref="System.Linq.IGrouping{T1,T2}" />.</param>
/// <returns>An <c>IQueryable<IGrouping<TKey, TElement>></c> in C# or <c>IQueryable(Of IGrouping(Of TKey, TElement))</c> in Visual Basic where each <see cref="System.Linq.IGrouping{T1,T2}" /> contains a sequence of objects of type <typeparamref name="TElement" /> and a key.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="source" /> or <paramref name="keySelector" /> or <paramref name="elementSelector" /> is <see langword="null" />.</exception>
/// <remarks>
/// <para>This method has at least one parameter of type <see cref="System.Linq.Expressions.Expression{T}" /> whose type argument is one of the <see cref="System.Func{T1,T2}" /> types. For these parameters, you can pass in a lambda expression and it will be compiled to an <see cref="System.Linq.Expressions.Expression{T}" />.</para>
/// <para>The <see cref="System.Linq.Queryable.GroupBy{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Linq.Expressions.Expression{System.Func{T1,T3}})" /> method generates a <see cref="System.Linq.Expressions.MethodCallExpression" /> that represents calling <see cref="System.Linq.Queryable.GroupBy{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Linq.Expressions.Expression{System.Func{T1,T3}})" /> itself as a constructed generic method. It then passes the <see cref="System.Linq.Expressions.MethodCallExpression" /> to the <see cref="System.Linq.IQueryProvider.CreateQuery{T}(System.Linq.Expressions.Expression)" /> method of the <see cref="System.Linq.IQueryProvider" /> represented by the <see cref="O:System.Linq.IQueryable.Provider" /> property of the <paramref name="source" /> parameter.</para>
/// <para>The query behavior that occurs as a result of executing an expression tree that represents calling <see cref="System.Linq.Queryable.GroupBy{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Linq.Expressions.Expression{System.Func{T1,T3}})" /> depends on the implementation of the type of the <paramref name="source" /> parameter. The expected behavior is that it groups the elements of <paramref name="source" /> by a key value that is obtained by invoking <paramref name="keySelector" /> on each element. It invokes <paramref name="elementSelector" /> on each element to obtain a result element.</para>
/// </remarks>
/// <example>The following code example demonstrates how to use <see cref="System.Linq.Queryable.GroupBy{T1,T2,T3}(System.Linq.IQueryable{T1},System.Linq.Expressions.Expression{System.Func{T1,T2}},System.Linq.Expressions.Expression{System.Func{T1,T3}})" /> to group the elements of a sequence.
/// :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Queryable/CS/queryable.cs" id="Snippet39":::
/// :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Queryable/VB/queryable.vb" id="Snippet39":::</example>
[DynamicDependency("GroupBy`3", typeof(Enumerable))]
public static IQueryable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (keySelector == null)
throw Error.ArgumentNull(nameof(keySelector));
if (elementSelector == null)
throw Error.ArgumentNull(nameof(elementSelector));
return source.Provider.CreateQuery<IGrouping<TKey, TElement>>(
Expression.Call(
null,
CachedReflectionInfo.GroupBy_TSource_TKey_TElement_3(typeof(TSource), typeof(TKey), typeof(TElement)),
source.Expression, Expression.Quote(keySelector), Expression.Quote(elementSelector)
));
}
/// <summary>Groups the elements of a sequence according to a specified key selector function and compares the keys by using a specified comparer.</summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by the function represented in <paramref name="keySelector" />.</typeparam>
/// <param name="source">An <see cref="System.Linq.IQueryable{T}" /> whose elements to group.</param>
/// <param name="keySelector">A function to extract the key for each element.</param>
/// <param name="comparer">An <see cref="System.Collections.Generic.IEqualityComparer{T}" /> to compare keys.</param>