QueryableEx.Generated.cs 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Globalization;
  7. using System.Linq.Expressions;
  8. using System.Reflection;
  9. namespace System.Linq
  10. {
  11. public static partial class QueryableEx
  12. {
  13. /// <summary>
  14. /// Determines whether an enumerable sequence is empty.
  15. /// </summary>
  16. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  17. /// <param name="source">Source sequence.</param>
  18. /// <returns>true if the sequence is empty; false otherwise.</returns>
  19. public static bool IsEmpty<TSource>(this IQueryable<TSource> source)
  20. {
  21. if (source == null)
  22. throw new ArgumentNullException(nameof(source));
  23. return source.Provider.Execute<bool>(
  24. Expression.Call(
  25. null,
  26. #if CRIPPLED_REFLECTION
  27. InfoOf(() => QueryableEx.IsEmpty<TSource>(default(IQueryable<TSource>))),
  28. #else
  29. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  30. #endif
  31. source.Expression
  32. )
  33. );
  34. }
  35. #pragma warning disable 1591
  36. [EditorBrowsable(EditorBrowsableState.Never)]
  37. public static bool IsEmpty<TSource>(IEnumerable<TSource> source)
  38. {
  39. return EnumerableEx.IsEmpty(source);
  40. }
  41. #pragma warning restore 1591
  42. /// <summary>
  43. /// Returns the minimum value in the enumerable sequence by using the specified comparer to compare values.
  44. /// </summary>
  45. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  46. /// <param name="source">Source sequence.</param>
  47. /// <param name="comparer">Comparer used to determine the minimum value.</param>
  48. /// <returns>Minimum value in the sequence.</returns>
  49. public static TSource Min<TSource>(this IQueryable<TSource> source, IComparer<TSource> comparer)
  50. {
  51. if (source == null)
  52. throw new ArgumentNullException(nameof(source));
  53. if (comparer == null)
  54. throw new ArgumentNullException(nameof(comparer));
  55. return source.Provider.Execute<TSource>(
  56. Expression.Call(
  57. null,
  58. #if CRIPPLED_REFLECTION
  59. InfoOf(() => QueryableEx.Min<TSource>(default(IQueryable<TSource>), default(IComparer<TSource>))),
  60. #else
  61. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  62. #endif
  63. source.Expression,
  64. Expression.Constant(comparer, typeof(IComparer<TSource>))
  65. )
  66. );
  67. }
  68. #pragma warning disable 1591
  69. [EditorBrowsable(EditorBrowsableState.Never)]
  70. public static TSource Min<TSource>(IEnumerable<TSource> source, IComparer<TSource> comparer)
  71. {
  72. return EnumerableEx.Min(source, comparer);
  73. }
  74. #pragma warning restore 1591
  75. /// <summary>
  76. /// Returns the elements with the minimum key value by using the default comparer to compare key values.
  77. /// </summary>
  78. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  79. /// <typeparam name="TKey">Key type.</typeparam>
  80. /// <param name="source">Source sequence.</param>
  81. /// <param name="keySelector">Key selector used to extract the key for each element in the sequence.</param>
  82. /// <returns>List with the elements that share the same minimum key value.</returns>
  83. public static IList<TSource> MinBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  84. {
  85. if (source == null)
  86. throw new ArgumentNullException(nameof(source));
  87. if (keySelector == null)
  88. throw new ArgumentNullException(nameof(keySelector));
  89. return source.Provider.Execute<IList<TSource>>(
  90. Expression.Call(
  91. null,
  92. #if CRIPPLED_REFLECTION
  93. InfoOf(() => QueryableEx.MinBy<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>))),
  94. #else
  95. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  96. #endif
  97. source.Expression,
  98. keySelector
  99. )
  100. );
  101. }
  102. #pragma warning disable 1591
  103. [EditorBrowsable(EditorBrowsableState.Never)]
  104. public static IList<TSource> MinBy<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
  105. {
  106. return EnumerableEx.MinBy(source, keySelector);
  107. }
  108. #pragma warning restore 1591
  109. /// <summary>
  110. /// Returns the elements with the minimum key value by using the specified comparer to compare key values.
  111. /// </summary>
  112. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  113. /// <typeparam name="TKey">Key type.</typeparam>
  114. /// <param name="source">Source sequence.</param>
  115. /// <param name="keySelector">Key selector used to extract the key for each element in the sequence.</param>
  116. /// <param name="comparer">Comparer used to determine the minimum key value.</param>
  117. /// <returns>List with the elements that share the same minimum key value.</returns>
  118. public static IList<TSource> MinBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
  119. {
  120. if (source == null)
  121. throw new ArgumentNullException(nameof(source));
  122. if (keySelector == null)
  123. throw new ArgumentNullException(nameof(keySelector));
  124. if (comparer == null)
  125. throw new ArgumentNullException(nameof(comparer));
  126. return source.Provider.Execute<IList<TSource>>(
  127. Expression.Call(
  128. null,
  129. #if CRIPPLED_REFLECTION
  130. InfoOf(() => QueryableEx.MinBy<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>), default(IComparer<TKey>))),
  131. #else
  132. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  133. #endif
  134. source.Expression,
  135. keySelector,
  136. Expression.Constant(comparer, typeof(IComparer<TKey>))
  137. )
  138. );
  139. }
  140. #pragma warning disable 1591
  141. [EditorBrowsable(EditorBrowsableState.Never)]
  142. public static IList<TSource> MinBy<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
  143. {
  144. return EnumerableEx.MinBy(source, keySelector, comparer);
  145. }
  146. #pragma warning restore 1591
  147. /// <summary>
  148. /// Returns the maximum value in the enumerable sequence by using the specified comparer to compare values.
  149. /// </summary>
  150. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  151. /// <param name="source">Source sequence.</param>
  152. /// <param name="comparer">Comparer used to determine the maximum value.</param>
  153. /// <returns>Maximum value in the sequence.</returns>
  154. public static TSource Max<TSource>(this IQueryable<TSource> source, IComparer<TSource> comparer)
  155. {
  156. if (source == null)
  157. throw new ArgumentNullException(nameof(source));
  158. if (comparer == null)
  159. throw new ArgumentNullException(nameof(comparer));
  160. return source.Provider.Execute<TSource>(
  161. Expression.Call(
  162. null,
  163. #if CRIPPLED_REFLECTION
  164. InfoOf(() => QueryableEx.Max<TSource>(default(IQueryable<TSource>), default(IComparer<TSource>))),
  165. #else
  166. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  167. #endif
  168. source.Expression,
  169. Expression.Constant(comparer, typeof(IComparer<TSource>))
  170. )
  171. );
  172. }
  173. #pragma warning disable 1591
  174. [EditorBrowsable(EditorBrowsableState.Never)]
  175. public static TSource Max<TSource>(IEnumerable<TSource> source, IComparer<TSource> comparer)
  176. {
  177. return EnumerableEx.Max(source, comparer);
  178. }
  179. #pragma warning restore 1591
  180. /// <summary>
  181. /// Returns the elements with the maximum key value by using the default comparer to compare key values.
  182. /// </summary>
  183. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  184. /// <typeparam name="TKey">Key type.</typeparam>
  185. /// <param name="source">Source sequence.</param>
  186. /// <param name="keySelector">Key selector used to extract the key for each element in the sequence.</param>
  187. /// <returns>List with the elements that share the same maximum key value.</returns>
  188. public static IList<TSource> MaxBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  189. {
  190. if (source == null)
  191. throw new ArgumentNullException(nameof(source));
  192. if (keySelector == null)
  193. throw new ArgumentNullException(nameof(keySelector));
  194. return source.Provider.Execute<IList<TSource>>(
  195. Expression.Call(
  196. null,
  197. #if CRIPPLED_REFLECTION
  198. InfoOf(() => QueryableEx.MaxBy<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>))),
  199. #else
  200. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  201. #endif
  202. source.Expression,
  203. keySelector
  204. )
  205. );
  206. }
  207. #pragma warning disable 1591
  208. [EditorBrowsable(EditorBrowsableState.Never)]
  209. public static IList<TSource> MaxBy<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
  210. {
  211. return EnumerableEx.MaxBy(source, keySelector);
  212. }
  213. #pragma warning restore 1591
  214. /// <summary>
  215. /// Returns the elements with the minimum key value by using the specified comparer to compare key values.
  216. /// </summary>
  217. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  218. /// <typeparam name="TKey">Key type.</typeparam>
  219. /// <param name="source">Source sequence.</param>
  220. /// <param name="keySelector">Key selector used to extract the key for each element in the sequence.</param>
  221. /// <param name="comparer">Comparer used to determine the maximum key value.</param>
  222. /// <returns>List with the elements that share the same maximum key value.</returns>
  223. public static IList<TSource> MaxBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
  224. {
  225. if (source == null)
  226. throw new ArgumentNullException(nameof(source));
  227. if (keySelector == null)
  228. throw new ArgumentNullException(nameof(keySelector));
  229. if (comparer == null)
  230. throw new ArgumentNullException(nameof(comparer));
  231. return source.Provider.Execute<IList<TSource>>(
  232. Expression.Call(
  233. null,
  234. #if CRIPPLED_REFLECTION
  235. InfoOf(() => QueryableEx.MaxBy<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>), default(IComparer<TKey>))),
  236. #else
  237. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  238. #endif
  239. source.Expression,
  240. keySelector,
  241. Expression.Constant(comparer, typeof(IComparer<TKey>))
  242. )
  243. );
  244. }
  245. #pragma warning disable 1591
  246. [EditorBrowsable(EditorBrowsableState.Never)]
  247. public static IList<TSource> MaxBy<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
  248. {
  249. return EnumerableEx.MaxBy(source, keySelector, comparer);
  250. }
  251. #pragma warning restore 1591
  252. /// <summary>
  253. /// Shares the source sequence within a selector function where each enumerator can fetch the next element from the source sequence.
  254. /// </summary>
  255. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  256. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  257. /// <param name="source">Source sequence.</param>
  258. /// <param name="selector">Selector function with shared access to the source sequence for each enumerator.</param>
  259. /// <returns>Sequence resulting from applying the selector function to the shared view over the source sequence.</returns>
  260. public static IQueryable<TResult> Share<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>> selector)
  261. {
  262. if (source == null)
  263. throw new ArgumentNullException(nameof(source));
  264. if (selector == null)
  265. throw new ArgumentNullException(nameof(selector));
  266. return source.Provider.CreateQuery<TResult>(
  267. Expression.Call(
  268. null,
  269. #if CRIPPLED_REFLECTION
  270. InfoOf(() => QueryableEx.Share<TSource, TResult>(default(IQueryable<TSource>), default(Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>>))),
  271. #else
  272. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
  273. #endif
  274. source.Expression,
  275. selector
  276. )
  277. );
  278. }
  279. #pragma warning disable 1591
  280. [EditorBrowsable(EditorBrowsableState.Never)]
  281. public static IEnumerable<TResult> Share<TSource, TResult>(IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
  282. {
  283. return EnumerableEx.Share(source, selector);
  284. }
  285. #pragma warning restore 1591
  286. /// <summary>
  287. /// Publishes the source sequence within a selector function where each enumerator can obtain a view over a tail of the source sequence.
  288. /// </summary>
  289. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  290. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  291. /// <param name="source">Source sequence.</param>
  292. /// <param name="selector">Selector function with published access to the source sequence for each enumerator.</param>
  293. /// <returns>Sequence resulting from applying the selector function to the published view over the source sequence.</returns>
  294. public static IQueryable<TResult> Publish<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>> selector)
  295. {
  296. if (source == null)
  297. throw new ArgumentNullException(nameof(source));
  298. if (selector == null)
  299. throw new ArgumentNullException(nameof(selector));
  300. return source.Provider.CreateQuery<TResult>(
  301. Expression.Call(
  302. null,
  303. #if CRIPPLED_REFLECTION
  304. InfoOf(() => QueryableEx.Publish<TSource, TResult>(default(IQueryable<TSource>), default(Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>>))),
  305. #else
  306. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
  307. #endif
  308. source.Expression,
  309. selector
  310. )
  311. );
  312. }
  313. #pragma warning disable 1591
  314. [EditorBrowsable(EditorBrowsableState.Never)]
  315. public static IEnumerable<TResult> Publish<TSource, TResult>(IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
  316. {
  317. return EnumerableEx.Publish(source, selector);
  318. }
  319. #pragma warning restore 1591
  320. /// <summary>
  321. /// Memoizes the source sequence within a selector function where each enumerator can get access to all of the sequence's elements without causing multiple enumerations over the source.
  322. /// </summary>
  323. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  324. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  325. /// <param name="source">Source sequence.</param>
  326. /// <param name="selector">Selector function with memoized access to the source sequence for each enumerator.</param>
  327. /// <returns>Sequence resulting from applying the selector function to the memoized view over the source sequence.</returns>
  328. public static IQueryable<TResult> Memoize<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>> selector)
  329. {
  330. if (source == null)
  331. throw new ArgumentNullException(nameof(source));
  332. if (selector == null)
  333. throw new ArgumentNullException(nameof(selector));
  334. return source.Provider.CreateQuery<TResult>(
  335. Expression.Call(
  336. null,
  337. #if CRIPPLED_REFLECTION
  338. InfoOf(() => QueryableEx.Memoize<TSource, TResult>(default(IQueryable<TSource>), default(Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>>))),
  339. #else
  340. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
  341. #endif
  342. source.Expression,
  343. selector
  344. )
  345. );
  346. }
  347. #pragma warning disable 1591
  348. [EditorBrowsable(EditorBrowsableState.Never)]
  349. public static IEnumerable<TResult> Memoize<TSource, TResult>(IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
  350. {
  351. return EnumerableEx.Memoize(source, selector);
  352. }
  353. #pragma warning restore 1591
  354. /// <summary>
  355. /// Memoizes the source sequence within a selector function where a specified number of enumerators can get access to all of the sequence's elements without causing multiple enumerations over the source.
  356. /// </summary>
  357. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  358. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  359. /// <param name="source">Source sequence.</param>
  360. /// <param name="readerCount">Number of enumerators that can access the underlying buffer. Once every enumerator has obtained an element from the buffer, the element is removed from the buffer.</param>
  361. /// <param name="selector">Selector function with memoized access to the source sequence for a specified number of enumerators.</param>
  362. /// <returns>Sequence resulting from applying the selector function to the memoized view over the source sequence.</returns>
  363. public static IQueryable<TResult> Memoize<TSource, TResult>(this IQueryable<TSource> source, int readerCount, Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>> selector)
  364. {
  365. if (source == null)
  366. throw new ArgumentNullException(nameof(source));
  367. if (selector == null)
  368. throw new ArgumentNullException(nameof(selector));
  369. return source.Provider.CreateQuery<TResult>(
  370. Expression.Call(
  371. null,
  372. #if CRIPPLED_REFLECTION
  373. InfoOf(() => QueryableEx.Memoize<TSource, TResult>(default(IQueryable<TSource>), default(int), default(Expression<Func<IEnumerable<TSource>, IEnumerable<TResult>>>))),
  374. #else
  375. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
  376. #endif
  377. source.Expression,
  378. Expression.Constant(readerCount, typeof(int)),
  379. selector
  380. )
  381. );
  382. }
  383. #pragma warning disable 1591
  384. [EditorBrowsable(EditorBrowsableState.Never)]
  385. public static IEnumerable<TResult> Memoize<TSource, TResult>(IEnumerable<TSource> source, int readerCount, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
  386. {
  387. return EnumerableEx.Memoize(source, readerCount, selector);
  388. }
  389. #pragma warning restore 1591
  390. /// <summary>
  391. /// Creates an enumerable sequence based on an enumerator factory function.
  392. /// </summary>
  393. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  394. /// <param name="provider">Query provider.</param>
  395. /// <param name="getEnumerator">Enumerator factory function.</param>
  396. /// <returns>Sequence that will invoke the enumerator factory upon a call to GetEnumerator.</returns>
  397. public static IQueryable<TResult> Create<TResult>(this IQueryProvider provider, Expression<Func<IEnumerator<TResult>>> getEnumerator)
  398. {
  399. if (provider == null)
  400. throw new ArgumentNullException(nameof(provider));
  401. if (getEnumerator == null)
  402. throw new ArgumentNullException(nameof(getEnumerator));
  403. return provider.CreateQuery<TResult>(
  404. Expression.Call(
  405. null,
  406. #if CRIPPLED_REFLECTION
  407. InfoOf(() => QueryableEx.Create<TResult>(default(IQueryProvider), default(Expression<Func<IEnumerator<TResult>>>))),
  408. #else
  409. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  410. #endif
  411. Expression.Constant(provider, typeof(IQueryProvider)),
  412. getEnumerator
  413. )
  414. );
  415. }
  416. #pragma warning disable 1591
  417. [EditorBrowsable(EditorBrowsableState.Never)]
  418. public static IEnumerable<TResult> Create<TResult>(Func<IEnumerator<TResult>> getEnumerator)
  419. {
  420. return EnumerableEx.Create(getEnumerator);
  421. }
  422. #pragma warning restore 1591
  423. /// <summary>
  424. /// Returns a sequence with a single element.
  425. /// </summary>
  426. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  427. /// <param name="provider">Query provider.</param>
  428. /// <param name="value">Single element of the resulting sequence.</param>
  429. /// <returns>Sequence with a single element.</returns>
  430. public static IQueryable<TResult> Return<TResult>(this IQueryProvider provider, TResult value)
  431. {
  432. if (provider == null)
  433. throw new ArgumentNullException(nameof(provider));
  434. return provider.CreateQuery<TResult>(
  435. Expression.Call(
  436. null,
  437. #if CRIPPLED_REFLECTION
  438. InfoOf(() => QueryableEx.Return<TResult>(default(IQueryProvider), default(TResult))),
  439. #else
  440. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  441. #endif
  442. Expression.Constant(provider, typeof(IQueryProvider)),
  443. Expression.Constant(value, typeof(TResult))
  444. )
  445. );
  446. }
  447. #pragma warning disable 1591
  448. [EditorBrowsable(EditorBrowsableState.Never)]
  449. public static /*!*/IQueryable<TResult> Return<TResult>(TResult value)
  450. {
  451. return EnumerableEx.Return(value).AsQueryable();
  452. }
  453. #pragma warning restore 1591
  454. /// <summary>
  455. /// Returns a sequence that throws an exception upon enumeration.
  456. /// </summary>
  457. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  458. /// <param name="provider">Query provider.</param>
  459. /// <param name="exception">Exception to throw upon enumerating the resulting sequence.</param>
  460. /// <returns>Sequence that throws the specified exception upon enumeration.</returns>
  461. public static IQueryable<TResult> Throw<TResult>(this IQueryProvider provider, Exception exception)
  462. {
  463. if (provider == null)
  464. throw new ArgumentNullException(nameof(provider));
  465. if (exception == null)
  466. throw new ArgumentNullException(nameof(exception));
  467. return provider.CreateQuery<TResult>(
  468. Expression.Call(
  469. null,
  470. #if CRIPPLED_REFLECTION
  471. InfoOf(() => QueryableEx.Throw<TResult>(default(IQueryProvider), default(Exception))),
  472. #else
  473. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  474. #endif
  475. Expression.Constant(provider, typeof(IQueryProvider)),
  476. Expression.Constant(exception, typeof(Exception))
  477. )
  478. );
  479. }
  480. #pragma warning disable 1591
  481. [EditorBrowsable(EditorBrowsableState.Never)]
  482. public static /*!*/IQueryable<TResult> Throw<TResult>(Exception exception)
  483. {
  484. return EnumerableEx.Throw<TResult>(exception).AsQueryable();
  485. }
  486. #pragma warning restore 1591
  487. /// <summary>
  488. /// Creates an enumerable sequence based on an enumerable factory function.
  489. /// </summary>
  490. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  491. /// <param name="provider">Query provider.</param>
  492. /// <param name="enumerableFactory">Enumerable factory function.</param>
  493. /// <returns>Sequence that will invoke the enumerable factory upon a call to GetEnumerator.</returns>
  494. public static IQueryable<TResult> Defer<TResult>(this IQueryProvider provider, Expression<Func<IEnumerable<TResult>>> enumerableFactory)
  495. {
  496. if (provider == null)
  497. throw new ArgumentNullException(nameof(provider));
  498. if (enumerableFactory == null)
  499. throw new ArgumentNullException(nameof(enumerableFactory));
  500. return provider.CreateQuery<TResult>(
  501. Expression.Call(
  502. null,
  503. #if CRIPPLED_REFLECTION
  504. InfoOf(() => QueryableEx.Defer<TResult>(default(IQueryProvider), default(Expression<Func<IEnumerable<TResult>>>))),
  505. #else
  506. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  507. #endif
  508. Expression.Constant(provider, typeof(IQueryProvider)),
  509. enumerableFactory
  510. )
  511. );
  512. }
  513. #pragma warning disable 1591
  514. [EditorBrowsable(EditorBrowsableState.Never)]
  515. public static /*!*/IQueryable<TResult> Defer<TResult>(Func<IEnumerable<TResult>> enumerableFactory)
  516. {
  517. return EnumerableEx.Defer(enumerableFactory).AsQueryable();
  518. }
  519. #pragma warning restore 1591
  520. /// <summary>
  521. /// Generates a sequence by mimicking a for loop.
  522. /// </summary>
  523. /// <typeparam name="TState">State type.</typeparam>
  524. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  525. /// <param name="provider">Query provider.</param>
  526. /// <param name="initialState">Initial state of the generator loop.</param>
  527. /// <param name="condition">Loop condition.</param>
  528. /// <param name="iterate">State update function to run after every iteration of the generator loop.</param>
  529. /// <param name="resultSelector">Result selector to compute resulting sequence elements.</param>
  530. /// <returns>Sequence obtained by running the generator loop, yielding computed elements.</returns>
  531. public static IQueryable<TResult> Generate<TState, TResult>(this IQueryProvider provider, TState initialState, Expression<Func<TState, bool>> condition, Expression<Func<TState, TState>> iterate, Expression<Func<TState, TResult>> resultSelector)
  532. {
  533. if (provider == null)
  534. throw new ArgumentNullException(nameof(provider));
  535. if (condition == null)
  536. throw new ArgumentNullException(nameof(condition));
  537. if (iterate == null)
  538. throw new ArgumentNullException(nameof(iterate));
  539. if (resultSelector == null)
  540. throw new ArgumentNullException(nameof(resultSelector));
  541. return provider.CreateQuery<TResult>(
  542. Expression.Call(
  543. null,
  544. #if CRIPPLED_REFLECTION
  545. InfoOf(() => QueryableEx.Generate<TState, TResult>(default(IQueryProvider), default(TState), default(Expression<Func<TState, bool>>), default(Expression<Func<TState, TState>>), default(Expression<Func<TState, TResult>>))),
  546. #else
  547. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TState), typeof(TResult)),
  548. #endif
  549. Expression.Constant(provider, typeof(IQueryProvider)),
  550. Expression.Constant(initialState),
  551. condition,
  552. iterate,
  553. resultSelector
  554. )
  555. );
  556. }
  557. #pragma warning disable 1591
  558. [EditorBrowsable(EditorBrowsableState.Never)]
  559. public static /*!*/IQueryable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector)
  560. {
  561. return EnumerableEx.Generate(initialState, condition, iterate, resultSelector).AsQueryable();
  562. }
  563. #pragma warning restore 1591
  564. /// <summary>
  565. /// Generates a sequence that's dependent on a resource object whose lifetime is determined by the sequence usage duration.
  566. /// </summary>
  567. /// <typeparam name="TSource">Source element type.</typeparam>
  568. /// <typeparam name="TResource">Resource type.</typeparam>
  569. /// <param name="provider">Query provider.</param>
  570. /// <param name="resourceFactory">Resource factory function.</param>
  571. /// <param name="enumerableFactory">Enumerable factory function, having access to the obtained resource.</param>
  572. /// <returns>Sequence whose use controls the lifetime of the associated obtained resource.</returns>
  573. public static IQueryable<TSource> Using<TSource, TResource>(this IQueryProvider provider, Expression<Func<TResource>> resourceFactory, Expression<Func<TResource, IEnumerable<TSource>>> enumerableFactory) where TResource : IDisposable
  574. {
  575. if (provider == null)
  576. throw new ArgumentNullException(nameof(provider));
  577. if (resourceFactory == null)
  578. throw new ArgumentNullException(nameof(resourceFactory));
  579. if (enumerableFactory == null)
  580. throw new ArgumentNullException(nameof(enumerableFactory));
  581. return provider.CreateQuery<TSource>(
  582. Expression.Call(
  583. null,
  584. #if CRIPPLED_REFLECTION
  585. InfoOf(() => QueryableEx.Using<TSource, TResource>(default(IQueryProvider), default(Expression<Func<TResource>>), default(Expression<Func<TResource, IEnumerable<TSource>>>))),
  586. #else
  587. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResource)),
  588. #endif
  589. Expression.Constant(provider, typeof(IQueryProvider)),
  590. resourceFactory,
  591. enumerableFactory
  592. )
  593. );
  594. }
  595. #pragma warning disable 1591
  596. [EditorBrowsable(EditorBrowsableState.Never)]
  597. public static /*!*/IQueryable<TSource> Using<TSource, TResource>(Func<TResource> resourceFactory, Func<TResource, IEnumerable<TSource>> enumerableFactory) where TResource : IDisposable
  598. {
  599. return EnumerableEx.Using(resourceFactory, enumerableFactory).AsQueryable();
  600. }
  601. #pragma warning restore 1591
  602. /// <summary>
  603. /// Generates a sequence by repeating the given value infinitely.
  604. /// </summary>
  605. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  606. /// <param name="provider">Query provider.</param>
  607. /// <param name="value">Value to repreat in the resulting sequence.</param>
  608. /// <returns>Sequence repeating the given value infinitely.</returns>
  609. public static IEnumerable<TResult> Repeat<TResult>(this IQueryProvider provider, TResult value)
  610. {
  611. if (provider == null)
  612. throw new ArgumentNullException(nameof(provider));
  613. return provider.CreateQuery<TResult>(
  614. Expression.Call(
  615. null,
  616. #if CRIPPLED_REFLECTION
  617. InfoOf(() => QueryableEx.Repeat<TResult>(default(IQueryProvider), default(TResult))),
  618. #else
  619. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  620. #endif
  621. Expression.Constant(provider, typeof(IQueryProvider)),
  622. Expression.Constant(value, typeof(TResult))
  623. )
  624. );
  625. }
  626. #pragma warning disable 1591
  627. [EditorBrowsable(EditorBrowsableState.Never)]
  628. public static /*!*/IQueryable<TResult> Repeat<TResult>(TResult value)
  629. {
  630. return EnumerableEx.Repeat(value).AsQueryable();
  631. }
  632. #pragma warning restore 1591
  633. /// <summary>
  634. /// Creates a sequence that corresponds to the source sequence, concatenating it with the sequence resulting from calling an exception handler function in case of an error.
  635. /// </summary>
  636. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  637. /// <typeparam name="TException">Exception type to catch.</typeparam>
  638. /// <param name="source">Source sequence.</param>
  639. /// <param name="handler">Handler to invoke when an exception of the specified type occurs.</param>
  640. /// <returns>Source sequence, concatenated with an exception handler result sequence in case of an error.</returns>
  641. public static IQueryable<TSource> Catch<TSource, TException>(this IQueryable<TSource> source, Expression<Func<TException, IEnumerable<TSource>>> handler)
  642. where TException : Exception
  643. {
  644. if (source == null)
  645. throw new ArgumentNullException(nameof(source));
  646. if (handler == null)
  647. throw new ArgumentNullException(nameof(handler));
  648. return source.Provider.CreateQuery<TSource>(
  649. Expression.Call(
  650. null,
  651. #if CRIPPLED_REFLECTION
  652. InfoOf(() => QueryableEx.Catch<TSource, TException>(default(IQueryable<TSource>), default(Expression<Func<TException, IEnumerable<TSource>>>))),
  653. #else
  654. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TException)),
  655. #endif
  656. source.Expression,
  657. handler
  658. )
  659. );
  660. }
  661. #pragma warning disable 1591
  662. [EditorBrowsable(EditorBrowsableState.Never)]
  663. public static IEnumerable<TSource> Catch<TSource, TException>(IEnumerable<TSource> source, Func<TException, IEnumerable<TSource>> handler)
  664. where TException : Exception
  665. {
  666. return EnumerableEx.Catch(source, handler);
  667. }
  668. #pragma warning restore 1591
  669. /// <summary>
  670. /// Creates a sequence by concatenating source sequences until a source sequence completes successfully.
  671. /// </summary>
  672. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  673. /// <param name="sources">Source sequences.</param>
  674. /// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>
  675. public static IQueryable<TSource> Catch<TSource>(this IQueryable<IEnumerable<TSource>> sources)
  676. {
  677. if (sources == null)
  678. throw new ArgumentNullException(nameof(sources));
  679. return sources.Provider.CreateQuery<TSource>(
  680. Expression.Call(
  681. null,
  682. #if CRIPPLED_REFLECTION
  683. InfoOf(() => QueryableEx.Catch<TSource>(default(IQueryable<IEnumerable<TSource>>))),
  684. #else
  685. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  686. #endif
  687. sources.Expression
  688. )
  689. );
  690. }
  691. #pragma warning disable 1591
  692. [EditorBrowsable(EditorBrowsableState.Never)]
  693. public static IEnumerable<TSource> Catch<TSource>(IEnumerable<IEnumerable<TSource>> sources)
  694. {
  695. return EnumerableEx.Catch(sources);
  696. }
  697. #pragma warning restore 1591
  698. /// <summary>
  699. /// Creates a sequence by concatenating source sequences until a source sequence completes successfully.
  700. /// </summary>
  701. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  702. /// <param name="provider">Query provider.</param>
  703. /// <param name="sources">Source sequences.</param>
  704. /// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>
  705. public static IQueryable<TSource> Catch<TSource>(this IQueryProvider provider, params IEnumerable<TSource>[] sources)
  706. {
  707. if (provider == null)
  708. throw new ArgumentNullException(nameof(provider));
  709. if (sources == null)
  710. throw new ArgumentNullException(nameof(sources));
  711. return provider.CreateQuery<TSource>(
  712. Expression.Call(
  713. null,
  714. #if CRIPPLED_REFLECTION
  715. InfoOf(() => QueryableEx.Catch<TSource>(default(IQueryProvider), default(IEnumerable<TSource>[]))),
  716. #else
  717. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  718. #endif
  719. Expression.Constant(provider, typeof(IQueryProvider)),
  720. GetSourceExpression(sources)
  721. )
  722. );
  723. }
  724. #pragma warning disable 1591
  725. [EditorBrowsable(EditorBrowsableState.Never)]
  726. public static /*!*/IQueryable<TSource> Catch<TSource>(params IEnumerable<TSource>[] sources)
  727. {
  728. return EnumerableEx.Catch(sources).AsQueryable();
  729. }
  730. #pragma warning restore 1591
  731. /// <summary>
  732. /// Creates a sequence that returns the elements of the first sequence, switching to the second in case of an error.
  733. /// </summary>
  734. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  735. /// <param name="first">First sequence.</param>
  736. /// <param name="second">Second sequence, concatenated to the result in case the first sequence completes exceptionally.</param>
  737. /// <returns>The first sequence, followed by the second sequence in case an error is produced.</returns>
  738. public static IQueryable<TSource> Catch<TSource>(this IQueryable<TSource> first, IEnumerable<TSource> second)
  739. {
  740. if (first == null)
  741. throw new ArgumentNullException(nameof(first));
  742. if (second == null)
  743. throw new ArgumentNullException(nameof(second));
  744. return first.Provider.CreateQuery<TSource>(
  745. Expression.Call(
  746. null,
  747. #if CRIPPLED_REFLECTION
  748. InfoOf(() => QueryableEx.Catch<TSource>(default(IQueryable<TSource>), default(IEnumerable<TSource>))),
  749. #else
  750. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  751. #endif
  752. first.Expression,
  753. GetSourceExpression(second)
  754. )
  755. );
  756. }
  757. #pragma warning disable 1591
  758. [EditorBrowsable(EditorBrowsableState.Never)]
  759. public static IEnumerable<TSource> Catch<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
  760. {
  761. return EnumerableEx.Catch(first, second);
  762. }
  763. #pragma warning restore 1591
  764. /// <summary>
  765. /// Creates a sequence whose termination or disposal of an enumerator causes a finally action to be executed.
  766. /// </summary>
  767. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  768. /// <param name="source">Source sequence.</param>
  769. /// <param name="finallyAction">Action to run upon termination of the sequence, or when an enumerator is disposed.</param>
  770. /// <returns>Source sequence with guarantees on the invocation of the finally action.</returns>
  771. public static IQueryable<TSource> Finally<TSource>(this IQueryable<TSource> source, Expression<Action> finallyAction)
  772. {
  773. if (source == null)
  774. throw new ArgumentNullException(nameof(source));
  775. if (finallyAction == null)
  776. throw new ArgumentNullException(nameof(finallyAction));
  777. return source.Provider.CreateQuery<TSource>(
  778. Expression.Call(
  779. null,
  780. #if CRIPPLED_REFLECTION
  781. InfoOf(() => QueryableEx.Finally<TSource>(default(IQueryable<TSource>), default(Expression<Action>))),
  782. #else
  783. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  784. #endif
  785. source.Expression,
  786. finallyAction
  787. )
  788. );
  789. }
  790. #pragma warning disable 1591
  791. [EditorBrowsable(EditorBrowsableState.Never)]
  792. public static IEnumerable<TSource> Finally<TSource>(IEnumerable<TSource> source, Action finallyAction)
  793. {
  794. return EnumerableEx.Finally(source, finallyAction);
  795. }
  796. #pragma warning restore 1591
  797. /// <summary>
  798. /// Creates a sequence that concatenates both given sequences, regardless of whether an error occurs.
  799. /// </summary>
  800. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  801. /// <param name="first">First sequence.</param>
  802. /// <param name="second">Second sequence.</param>
  803. /// <returns>Sequence concatenating the elements of both sequences, ignoring errors.</returns>
  804. public static IQueryable<TSource> OnErrorResumeNext<TSource>(this IQueryable<TSource> first, IEnumerable<TSource> second)
  805. {
  806. if (first == null)
  807. throw new ArgumentNullException(nameof(first));
  808. if (second == null)
  809. throw new ArgumentNullException(nameof(second));
  810. return first.Provider.CreateQuery<TSource>(
  811. Expression.Call(
  812. null,
  813. #if CRIPPLED_REFLECTION
  814. InfoOf(() => QueryableEx.OnErrorResumeNext<TSource>(default(IQueryable<TSource>), default(IEnumerable<TSource>))),
  815. #else
  816. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  817. #endif
  818. first.Expression,
  819. GetSourceExpression(second)
  820. )
  821. );
  822. }
  823. #pragma warning disable 1591
  824. [EditorBrowsable(EditorBrowsableState.Never)]
  825. public static IEnumerable<TSource> OnErrorResumeNext<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
  826. {
  827. return EnumerableEx.OnErrorResumeNext(first, second);
  828. }
  829. #pragma warning restore 1591
  830. /// <summary>
  831. /// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the sequences.
  832. /// </summary>
  833. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  834. /// <param name="provider">Query provider.</param>
  835. /// <param name="sources">Source sequences.</param>
  836. /// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
  837. public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IQueryProvider provider, params IEnumerable<TSource>[] sources)
  838. {
  839. if (provider == null)
  840. throw new ArgumentNullException(nameof(provider));
  841. if (sources == null)
  842. throw new ArgumentNullException(nameof(sources));
  843. return provider.CreateQuery<TSource>(
  844. Expression.Call(
  845. null,
  846. #if CRIPPLED_REFLECTION
  847. InfoOf(() => QueryableEx.OnErrorResumeNext<TSource>(default(IQueryProvider), default(IEnumerable<TSource>[]))),
  848. #else
  849. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  850. #endif
  851. Expression.Constant(provider, typeof(IQueryProvider)),
  852. GetSourceExpression(sources)
  853. )
  854. );
  855. }
  856. #pragma warning disable 1591
  857. [EditorBrowsable(EditorBrowsableState.Never)]
  858. public static /*!*/IQueryable<TSource> OnErrorResumeNext<TSource>(params IEnumerable<TSource>[] sources)
  859. {
  860. return EnumerableEx.OnErrorResumeNext(sources).AsQueryable();
  861. }
  862. #pragma warning restore 1591
  863. /// <summary>
  864. /// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the sequences.
  865. /// </summary>
  866. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  867. /// <param name="sources">Source sequences.</param>
  868. /// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
  869. public static IQueryable<TSource> OnErrorResumeNext<TSource>(this IQueryable<IEnumerable<TSource>> sources)
  870. {
  871. if (sources == null)
  872. throw new ArgumentNullException(nameof(sources));
  873. return sources.Provider.CreateQuery<TSource>(
  874. Expression.Call(
  875. null,
  876. #if CRIPPLED_REFLECTION
  877. InfoOf(() => QueryableEx.OnErrorResumeNext<TSource>(default(IQueryable<IEnumerable<TSource>>))),
  878. #else
  879. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  880. #endif
  881. sources.Expression
  882. )
  883. );
  884. }
  885. #pragma warning disable 1591
  886. [EditorBrowsable(EditorBrowsableState.Never)]
  887. public static IEnumerable<TSource> OnErrorResumeNext<TSource>(IEnumerable<IEnumerable<TSource>> sources)
  888. {
  889. return EnumerableEx.OnErrorResumeNext(sources);
  890. }
  891. #pragma warning restore 1591
  892. /// <summary>
  893. /// Creates a sequence that retries enumerating the source sequence as long as an error occurs.
  894. /// </summary>
  895. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  896. /// <param name="source">Source sequence.</param>
  897. /// <returns>Sequence concatenating the results of the source sequence as long as an error occurs.</returns>
  898. public static IQueryable<TSource> Retry<TSource>(this IQueryable<TSource> source)
  899. {
  900. if (source == null)
  901. throw new ArgumentNullException(nameof(source));
  902. return source.Provider.CreateQuery<TSource>(
  903. Expression.Call(
  904. null,
  905. #if CRIPPLED_REFLECTION
  906. InfoOf(() => QueryableEx.Retry<TSource>(default(IQueryable<TSource>))),
  907. #else
  908. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  909. #endif
  910. source.Expression
  911. )
  912. );
  913. }
  914. #pragma warning disable 1591
  915. [EditorBrowsable(EditorBrowsableState.Never)]
  916. public static IEnumerable<TSource> Retry<TSource>(IEnumerable<TSource> source)
  917. {
  918. return EnumerableEx.Retry(source);
  919. }
  920. #pragma warning restore 1591
  921. /// <summary>
  922. /// Creates a sequence that retries enumerating the source sequence as long as an error occurs, with the specified maximum number of retries.
  923. /// </summary>
  924. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  925. /// <param name="source">Source sequence.</param>
  926. /// <param name="retryCount">Maximum number of retries.</param>
  927. /// <returns>Sequence concatenating the results of the source sequence as long as an error occurs.</returns>
  928. public static IQueryable<TSource> Retry<TSource>(this IQueryable<TSource> source, int retryCount)
  929. {
  930. if (source == null)
  931. throw new ArgumentNullException(nameof(source));
  932. return source.Provider.CreateQuery<TSource>(
  933. Expression.Call(
  934. null,
  935. #if CRIPPLED_REFLECTION
  936. InfoOf(() => QueryableEx.Retry<TSource>(default(IQueryable<TSource>), default(int))),
  937. #else
  938. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  939. #endif
  940. source.Expression,
  941. Expression.Constant(retryCount, typeof(int))
  942. )
  943. );
  944. }
  945. #pragma warning disable 1591
  946. [EditorBrowsable(EditorBrowsableState.Never)]
  947. public static IEnumerable<TSource> Retry<TSource>(IEnumerable<TSource> source, int retryCount)
  948. {
  949. return EnumerableEx.Retry(source, retryCount);
  950. }
  951. #pragma warning restore 1591
  952. /// <summary>
  953. /// Generates an enumerable sequence by repeating a source sequence as long as the given loop condition holds.
  954. /// </summary>
  955. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  956. /// <param name="provider">Query provider.</param>
  957. /// <param name="condition">Loop condition.</param>
  958. /// <param name="source">Sequence to repeat while the condition evaluates true.</param>
  959. /// <returns>Sequence generated by repeating the given sequence while the condition evaluates to true.</returns>
  960. public static IQueryable<TResult> While<TResult>(this IQueryProvider provider, Expression<Func<bool>> condition, IEnumerable<TResult> source)
  961. {
  962. if (provider == null)
  963. throw new ArgumentNullException(nameof(provider));
  964. if (condition == null)
  965. throw new ArgumentNullException(nameof(condition));
  966. if (source == null)
  967. throw new ArgumentNullException(nameof(source));
  968. return provider.CreateQuery<TResult>(
  969. Expression.Call(
  970. null,
  971. #if CRIPPLED_REFLECTION
  972. InfoOf(() => QueryableEx.While<TResult>(default(IQueryProvider), default(Expression<Func<bool>>), default(IEnumerable<TResult>))),
  973. #else
  974. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  975. #endif
  976. Expression.Constant(provider, typeof(IQueryProvider)),
  977. condition,
  978. GetSourceExpression(source)
  979. )
  980. );
  981. }
  982. #pragma warning disable 1591
  983. [EditorBrowsable(EditorBrowsableState.Never)]
  984. public static /*!*/IQueryable<TResult> While<TResult>(Func<bool> condition, IEnumerable<TResult> source)
  985. {
  986. return EnumerableEx.While(condition, source).AsQueryable();
  987. }
  988. #pragma warning restore 1591
  989. /// <summary>
  990. /// Returns an enumerable sequence based on the evaluation result of the given condition.
  991. /// </summary>
  992. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  993. /// <param name="provider">Query provider.</param>
  994. /// <param name="condition">Condition to evaluate.</param>
  995. /// <param name="thenSource">Sequence to return in case the condition evaluates true.</param>
  996. /// <param name="elseSource">Sequence to return in case the condition evaluates false.</param>
  997. /// <returns>Either of the two input sequences based on the result of evaluating the condition.</returns>
  998. public static IQueryable<TResult> If<TResult>(this IQueryProvider provider, Expression<Func<bool>> condition, IEnumerable<TResult> thenSource, IEnumerable<TResult> elseSource)
  999. {
  1000. if (provider == null)
  1001. throw new ArgumentNullException(nameof(provider));
  1002. if (condition == null)
  1003. throw new ArgumentNullException(nameof(condition));
  1004. if (thenSource == null)
  1005. throw new ArgumentNullException(nameof(thenSource));
  1006. if (elseSource == null)
  1007. throw new ArgumentNullException(nameof(elseSource));
  1008. return provider.CreateQuery<TResult>(
  1009. Expression.Call(
  1010. null,
  1011. #if CRIPPLED_REFLECTION
  1012. InfoOf(() => QueryableEx.If<TResult>(default(IQueryProvider), default(Expression<Func<bool>>), default(IEnumerable<TResult>), default(IEnumerable<TResult>))),
  1013. #else
  1014. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  1015. #endif
  1016. Expression.Constant(provider, typeof(IQueryProvider)),
  1017. condition,
  1018. GetSourceExpression(thenSource),
  1019. GetSourceExpression(elseSource)
  1020. )
  1021. );
  1022. }
  1023. #pragma warning disable 1591
  1024. [EditorBrowsable(EditorBrowsableState.Never)]
  1025. public static /*!*/IQueryable<TResult> If<TResult>(Func<bool> condition, IEnumerable<TResult> thenSource, IEnumerable<TResult> elseSource)
  1026. {
  1027. return EnumerableEx.If(condition, thenSource, elseSource).AsQueryable();
  1028. }
  1029. #pragma warning restore 1591
  1030. /// <summary>
  1031. /// Returns an enumerable sequence if the evaluation result of the given condition is true, otherwise returns an empty sequence.
  1032. /// </summary>
  1033. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  1034. /// <param name="provider">Query provider.</param>
  1035. /// <param name="condition">Condition to evaluate.</param>
  1036. /// <param name="thenSource">Sequence to return in case the condition evaluates true.</param>
  1037. /// <returns>The given input sequence if the condition evaluates true; otherwise, an empty sequence.</returns>
  1038. public static IQueryable<TResult> If<TResult>(this IQueryProvider provider, Expression<Func<bool>> condition, IEnumerable<TResult> thenSource)
  1039. {
  1040. if (provider == null)
  1041. throw new ArgumentNullException(nameof(provider));
  1042. if (condition == null)
  1043. throw new ArgumentNullException(nameof(condition));
  1044. if (thenSource == null)
  1045. throw new ArgumentNullException(nameof(thenSource));
  1046. return provider.CreateQuery<TResult>(
  1047. Expression.Call(
  1048. null,
  1049. #if CRIPPLED_REFLECTION
  1050. InfoOf(() => QueryableEx.If<TResult>(default(IQueryProvider), default(Expression<Func<bool>>), default(IEnumerable<TResult>))),
  1051. #else
  1052. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  1053. #endif
  1054. Expression.Constant(provider, typeof(IQueryProvider)),
  1055. condition,
  1056. GetSourceExpression(thenSource)
  1057. )
  1058. );
  1059. }
  1060. #pragma warning disable 1591
  1061. [EditorBrowsable(EditorBrowsableState.Never)]
  1062. public static /*!*/IQueryable<TResult> If<TResult>(Func<bool> condition, IEnumerable<TResult> thenSource)
  1063. {
  1064. return EnumerableEx.If(condition, thenSource).AsQueryable();
  1065. }
  1066. #pragma warning restore 1591
  1067. /// <summary>
  1068. /// Generates an enumerable sequence by repeating a source sequence as long as the given loop postcondition holds.
  1069. /// </summary>
  1070. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  1071. /// <param name="source">Source sequence to repeat while the condition evaluates true.</param>
  1072. /// <param name="condition">Loop condition.</param>
  1073. /// <returns>Sequence generated by repeating the given sequence until the condition evaluates to false.</returns>
  1074. public static IQueryable<TResult> DoWhile<TResult>(this IQueryable<TResult> source, Expression<Func<bool>> condition)
  1075. {
  1076. if (source == null)
  1077. throw new ArgumentNullException(nameof(source));
  1078. if (condition == null)
  1079. throw new ArgumentNullException(nameof(condition));
  1080. return source.Provider.CreateQuery<TResult>(
  1081. Expression.Call(
  1082. null,
  1083. #if CRIPPLED_REFLECTION
  1084. InfoOf(() => QueryableEx.DoWhile<TResult>(default(IQueryable<TResult>), default(Expression<Func<bool>>))),
  1085. #else
  1086. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  1087. #endif
  1088. source.Expression,
  1089. condition
  1090. )
  1091. );
  1092. }
  1093. #pragma warning disable 1591
  1094. [EditorBrowsable(EditorBrowsableState.Never)]
  1095. public static IEnumerable<TResult> DoWhile<TResult>(IEnumerable<TResult> source, Func<bool> condition)
  1096. {
  1097. return EnumerableEx.DoWhile(source, condition);
  1098. }
  1099. #pragma warning restore 1591
  1100. /// <summary>
  1101. /// Returns a sequence from a dictionary based on the result of evaluating a selector function.
  1102. /// </summary>
  1103. /// <typeparam name="TValue">Type of the selector value.</typeparam>
  1104. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  1105. /// <param name="provider">Query provider.</param>
  1106. /// <param name="selector">Selector function used to pick a sequence from the given sources.</param>
  1107. /// <param name="sources">Dictionary mapping selector values onto resulting sequences.</param>
  1108. /// <returns>The source sequence corresponding with the evaluated selector value; otherwise, an empty sequence.</returns>
  1109. public static IQueryable<TResult> Case<TValue, TResult>(this IQueryProvider provider, Expression<Func<TValue>> selector, IDictionary<TValue, IEnumerable<TResult>> sources)
  1110. {
  1111. if (provider == null)
  1112. throw new ArgumentNullException(nameof(provider));
  1113. if (selector == null)
  1114. throw new ArgumentNullException(nameof(selector));
  1115. if (sources == null)
  1116. throw new ArgumentNullException(nameof(sources));
  1117. return provider.CreateQuery<TResult>(
  1118. Expression.Call(
  1119. null,
  1120. #if CRIPPLED_REFLECTION
  1121. InfoOf(() => QueryableEx.Case<TValue, TResult>(default(IQueryProvider), default(Expression<Func<TValue>>), default(IDictionary<TValue, IEnumerable<TResult>>))),
  1122. #else
  1123. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TValue), typeof(TResult)),
  1124. #endif
  1125. selector,
  1126. Expression.Constant(sources, typeof(IDictionary<TValue, IEnumerable<TResult>>))
  1127. )
  1128. );
  1129. }
  1130. #pragma warning disable 1591
  1131. [EditorBrowsable(EditorBrowsableState.Never)]
  1132. public static /*!*/IQueryable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IEnumerable<TResult>> sources)
  1133. {
  1134. return EnumerableEx.Case(selector, sources).AsQueryable();
  1135. }
  1136. #pragma warning restore 1591
  1137. /// <summary>
  1138. /// Returns a sequence from a dictionary based on the result of evaluating a selector function, also specifying a default sequence.
  1139. /// </summary>
  1140. /// <typeparam name="TValue">Type of the selector value.</typeparam>
  1141. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  1142. /// <param name="provider">Query provider.</param>
  1143. /// <param name="selector">Selector function used to pick a sequence from the given sources.</param>
  1144. /// <param name="sources">Dictionary mapping selector values onto resulting sequences.</param>
  1145. /// <param name="defaultSource">Default sequence to return in case there's no corresponding source for the computed selector value.</param>
  1146. /// <returns>The source sequence corresponding with the evaluated selector value; otherwise, the default source.</returns>
  1147. public static IQueryable<TResult> Case<TValue, TResult>(this IQueryProvider provider, Expression<Func<TValue>> selector, IDictionary<TValue, IEnumerable<TResult>> sources, IEnumerable<TResult> defaultSource)
  1148. {
  1149. if (provider == null)
  1150. throw new ArgumentNullException(nameof(provider));
  1151. if (selector == null)
  1152. throw new ArgumentNullException(nameof(selector));
  1153. if (sources == null)
  1154. throw new ArgumentNullException(nameof(sources));
  1155. if (defaultSource == null)
  1156. throw new ArgumentNullException(nameof(defaultSource));
  1157. return provider.CreateQuery<TResult>(
  1158. Expression.Call(
  1159. null,
  1160. #if CRIPPLED_REFLECTION
  1161. InfoOf(() => QueryableEx.Case<TValue, TResult>(default(IQueryProvider), default(Expression<Func<TValue>>), default(IDictionary<TValue, IEnumerable<TResult>>), default(IEnumerable<TResult>))),
  1162. #else
  1163. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TValue), typeof(TResult)),
  1164. #endif
  1165. selector,
  1166. Expression.Constant(sources, typeof(IDictionary<TValue, IEnumerable<TResult>>))
  1167. )
  1168. );
  1169. }
  1170. #pragma warning disable 1591
  1171. [EditorBrowsable(EditorBrowsableState.Never)]
  1172. public static /*!*/IQueryable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IEnumerable<TResult>> sources, IEnumerable<TResult> defaultSource)
  1173. {
  1174. return EnumerableEx.Case(selector, sources, defaultSource).AsQueryable();
  1175. }
  1176. #pragma warning restore 1591
  1177. /// <summary>
  1178. /// Generates a sequence by enumerating a source sequence, mapping its elements on result sequences, and concatenating those sequences.
  1179. /// </summary>
  1180. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1181. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  1182. /// <param name="provider">Query provider.</param>
  1183. /// <param name="source">Source sequence.</param>
  1184. /// <param name="resultSelector">Result selector to evaluate for each iteration over the source.</param>
  1185. /// <returns>Sequence concatenating the inner sequences that result from evaluating the result selector on elements from the source.</returns>
  1186. public static IQueryable<TResult> For<TSource, TResult>(this IQueryProvider provider, IEnumerable<TSource> source, Expression<Func<TSource, IEnumerable<TResult>>> resultSelector)
  1187. {
  1188. if (provider == null)
  1189. throw new ArgumentNullException(nameof(provider));
  1190. if (source == null)
  1191. throw new ArgumentNullException(nameof(source));
  1192. if (resultSelector == null)
  1193. throw new ArgumentNullException(nameof(resultSelector));
  1194. return provider.CreateQuery<TResult>(
  1195. Expression.Call(
  1196. null,
  1197. #if CRIPPLED_REFLECTION
  1198. InfoOf(() => QueryableEx.For<TSource, TResult>(default(IQueryProvider), default(IEnumerable<TSource>), default(Expression<Func<TSource, IEnumerable<TResult>>>))),
  1199. #else
  1200. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
  1201. #endif
  1202. GetSourceExpression(source),
  1203. resultSelector
  1204. )
  1205. );
  1206. }
  1207. #pragma warning disable 1591
  1208. [EditorBrowsable(EditorBrowsableState.Never)]
  1209. public static /*!*/IQueryable<TResult> For<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector)
  1210. {
  1211. return EnumerableEx.For(source, resultSelector).AsQueryable();
  1212. }
  1213. #pragma warning restore 1591
  1214. /// <summary>
  1215. /// Concatenates the input sequences.
  1216. /// </summary>
  1217. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1218. /// <param name="sources">Source sequences.</param>
  1219. /// <returns>Sequence with the elements of the source sequences concatenated.</returns>
  1220. public static IQueryable<TSource> Concat<TSource>(this IQueryable<IEnumerable<TSource>> sources)
  1221. {
  1222. if (sources == null)
  1223. throw new ArgumentNullException(nameof(sources));
  1224. return sources.Provider.CreateQuery<TSource>(
  1225. Expression.Call(
  1226. null,
  1227. #if CRIPPLED_REFLECTION
  1228. InfoOf(() => QueryableEx.Concat<TSource>(default(IQueryable<IEnumerable<TSource>>))),
  1229. #else
  1230. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1231. #endif
  1232. GetSourceExpression(sources)
  1233. )
  1234. );
  1235. }
  1236. #pragma warning disable 1591
  1237. [EditorBrowsable(EditorBrowsableState.Never)]
  1238. public static IEnumerable<TSource> Concat<TSource>(IEnumerable<IEnumerable<TSource>> sources)
  1239. {
  1240. return EnumerableEx.Concat(sources);
  1241. }
  1242. #pragma warning restore 1591
  1243. /// <summary>
  1244. /// Concatenates the input sequences.
  1245. /// </summary>
  1246. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1247. /// <param name="provider">Query provider.</param>
  1248. /// <param name="sources">Source sequences.</param>
  1249. /// <returns>Sequence with the elements of the source sequences concatenated.</returns>
  1250. public static IQueryable<TSource> Concat<TSource>(this IQueryProvider provider, params IEnumerable<TSource>[] sources)
  1251. {
  1252. if (provider == null)
  1253. throw new ArgumentNullException(nameof(provider));
  1254. if (sources == null)
  1255. throw new ArgumentNullException(nameof(sources));
  1256. return provider.CreateQuery<TSource>(
  1257. Expression.Call(
  1258. null,
  1259. #if CRIPPLED_REFLECTION
  1260. InfoOf(() => QueryableEx.Concat<TSource>(default(IQueryProvider), default(IEnumerable<TSource>[]))),
  1261. #else
  1262. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1263. #endif
  1264. Expression.Constant(provider, typeof(IQueryProvider)),
  1265. GetSourceExpression(sources)
  1266. )
  1267. );
  1268. }
  1269. #pragma warning disable 1591
  1270. [EditorBrowsable(EditorBrowsableState.Never)]
  1271. public static /*!*/IQueryable<TSource> Concat<TSource>(params IEnumerable<TSource>[] sources)
  1272. {
  1273. return EnumerableEx.Concat(sources).AsQueryable();
  1274. }
  1275. #pragma warning restore 1591
  1276. /// <summary>
  1277. /// Projects each element of a sequence to an given sequence and flattens the resulting sequences into one sequence.
  1278. /// </summary>
  1279. /// <typeparam name="TSource">First source sequence element type.</typeparam>
  1280. /// <typeparam name="TOther">Second source sequence element type.</typeparam>
  1281. /// <param name="source">A sequence of values to project.</param>
  1282. /// <param name="other">Inner sequence each source sequenec element is projected onto.</param>
  1283. /// <returns>Sequence flattening the sequences that result from projecting elements in the source sequence.</returns>
  1284. public static IQueryable<TOther> SelectMany<TSource, TOther>(this IQueryable<TSource> source, IEnumerable<TOther> other)
  1285. {
  1286. if (source == null)
  1287. throw new ArgumentNullException(nameof(source));
  1288. if (other == null)
  1289. throw new ArgumentNullException(nameof(other));
  1290. return source.Provider.CreateQuery<TOther>(
  1291. Expression.Call(
  1292. null,
  1293. #if CRIPPLED_REFLECTION
  1294. InfoOf(() => QueryableEx.SelectMany<TSource, TOther>(default(IQueryable<TSource>), default(IEnumerable<TOther>))),
  1295. #else
  1296. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TOther)),
  1297. #endif
  1298. source.Expression,
  1299. GetSourceExpression(other)
  1300. )
  1301. );
  1302. }
  1303. #pragma warning disable 1591
  1304. [EditorBrowsable(EditorBrowsableState.Never)]
  1305. public static IEnumerable<TOther> SelectMany<TSource, TOther>(IEnumerable<TSource> source, IEnumerable<TOther> other)
  1306. {
  1307. return EnumerableEx.SelectMany(source, other);
  1308. }
  1309. #pragma warning restore 1591
  1310. /// <summary>
  1311. /// Hides the enumerable sequence object identity.
  1312. /// </summary>
  1313. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1314. /// <param name="source">Source sequence.</param>
  1315. /// <returns>Enumerable sequence with the same behavior as the original, but hiding the source object identity.</returns>
  1316. /// <remarks>AsQueryable doesn't hide the object identity, and simply acts as a cast to the IQueryable&lt;TSource&gt; interface.</remarks>
  1317. public static IQueryable<TSource> Hide<TSource>(this IQueryable<TSource> source)
  1318. {
  1319. if (source == null)
  1320. throw new ArgumentNullException(nameof(source));
  1321. return source.Provider.CreateQuery<TSource>(
  1322. Expression.Call(
  1323. null,
  1324. #if CRIPPLED_REFLECTION
  1325. InfoOf(() => QueryableEx.Hide<TSource>(default(IQueryable<TSource>))),
  1326. #else
  1327. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1328. #endif
  1329. source.Expression
  1330. )
  1331. );
  1332. }
  1333. #pragma warning disable 1591
  1334. [EditorBrowsable(EditorBrowsableState.Never)]
  1335. public static IEnumerable<TSource> Hide<TSource>(IEnumerable<TSource> source)
  1336. {
  1337. return EnumerableEx.Hide(source);
  1338. }
  1339. #pragma warning restore 1591
  1340. /// <summary>
  1341. /// Lazily invokes an action for each value in the sequence.
  1342. /// </summary>
  1343. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1344. /// <param name="source">Source sequence.</param>
  1345. /// <param name="onNext">Action to invoke for each element.</param>
  1346. /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>
  1347. public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, Expression<Action<TSource>> onNext)
  1348. {
  1349. if (source == null)
  1350. throw new ArgumentNullException(nameof(source));
  1351. if (onNext == null)
  1352. throw new ArgumentNullException(nameof(onNext));
  1353. return source.Provider.CreateQuery<TSource>(
  1354. Expression.Call(
  1355. null,
  1356. #if CRIPPLED_REFLECTION
  1357. InfoOf(() => QueryableEx.Do<TSource>(default(IQueryable<TSource>), default(Expression<Action<TSource>>))),
  1358. #else
  1359. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1360. #endif
  1361. source.Expression,
  1362. onNext
  1363. )
  1364. );
  1365. }
  1366. #pragma warning disable 1591
  1367. [EditorBrowsable(EditorBrowsableState.Never)]
  1368. public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, Action<TSource> onNext)
  1369. {
  1370. return EnumerableEx.Do(source, onNext);
  1371. }
  1372. #pragma warning restore 1591
  1373. /// <summary>
  1374. /// Lazily invokes an action for each value in the sequence, and executes an action for successful termination.
  1375. /// </summary>
  1376. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1377. /// <param name="source">Source sequence.</param>
  1378. /// <param name="onNext">Action to invoke for each element.</param>
  1379. /// <param name="onCompleted">Action to invoke on successful termination of the sequence.</param>
  1380. /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>
  1381. public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, Expression<Action<TSource>> onNext, Expression<Action> onCompleted)
  1382. {
  1383. if (source == null)
  1384. throw new ArgumentNullException(nameof(source));
  1385. if (onNext == null)
  1386. throw new ArgumentNullException(nameof(onNext));
  1387. if (onCompleted == null)
  1388. throw new ArgumentNullException(nameof(onCompleted));
  1389. return source.Provider.CreateQuery<TSource>(
  1390. Expression.Call(
  1391. null,
  1392. #if CRIPPLED_REFLECTION
  1393. InfoOf(() => QueryableEx.Do<TSource>(default(IQueryable<TSource>), default(Expression<Action<TSource>>), default(Expression<Action>))),
  1394. #else
  1395. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1396. #endif
  1397. source.Expression,
  1398. onNext,
  1399. onCompleted
  1400. )
  1401. );
  1402. }
  1403. #pragma warning disable 1591
  1404. [EditorBrowsable(EditorBrowsableState.Never)]
  1405. public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, Action<TSource> onNext, Action onCompleted)
  1406. {
  1407. return EnumerableEx.Do(source, onNext, onCompleted);
  1408. }
  1409. #pragma warning restore 1591
  1410. /// <summary>
  1411. /// Lazily invokes an action for each value in the sequence, and executes an action upon exceptional termination.
  1412. /// </summary>
  1413. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1414. /// <param name="source">Source sequence.</param>
  1415. /// <param name="onNext">Action to invoke for each element.</param>
  1416. /// <param name="onError">Action to invoke on exceptional termination of the sequence.</param>
  1417. /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>
  1418. public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, Expression<Action<TSource>> onNext, Expression<Action<Exception>> onError)
  1419. {
  1420. if (source == null)
  1421. throw new ArgumentNullException(nameof(source));
  1422. if (onNext == null)
  1423. throw new ArgumentNullException(nameof(onNext));
  1424. if (onError == null)
  1425. throw new ArgumentNullException(nameof(onError));
  1426. return source.Provider.CreateQuery<TSource>(
  1427. Expression.Call(
  1428. null,
  1429. #if CRIPPLED_REFLECTION
  1430. InfoOf(() => QueryableEx.Do<TSource>(default(IQueryable<TSource>), default(Expression<Action<TSource>>), default(Expression<Action<Exception>>))),
  1431. #else
  1432. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1433. #endif
  1434. source.Expression,
  1435. onNext,
  1436. onError
  1437. )
  1438. );
  1439. }
  1440. #pragma warning disable 1591
  1441. [EditorBrowsable(EditorBrowsableState.Never)]
  1442. public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError)
  1443. {
  1444. return EnumerableEx.Do(source, onNext, onError);
  1445. }
  1446. #pragma warning restore 1591
  1447. /// <summary>
  1448. /// Lazily invokes an action for each value in the sequence, and executes an action upon successful or exceptional termination.
  1449. /// </summary>
  1450. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1451. /// <param name="source">Source sequence.</param>
  1452. /// <param name="onNext">Action to invoke for each element.</param>
  1453. /// <param name="onError">Action to invoke on exceptional termination of the sequence.</param>
  1454. /// <param name="onCompleted">Action to invoke on successful termination of the sequence.</param>
  1455. /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>
  1456. public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, Expression<Action<TSource>> onNext, Expression<Action<Exception>> onError, Expression<Action> onCompleted)
  1457. {
  1458. if (source == null)
  1459. throw new ArgumentNullException(nameof(source));
  1460. if (onNext == null)
  1461. throw new ArgumentNullException(nameof(onNext));
  1462. if (onError == null)
  1463. throw new ArgumentNullException(nameof(onError));
  1464. if (onCompleted == null)
  1465. throw new ArgumentNullException(nameof(onCompleted));
  1466. return source.Provider.CreateQuery<TSource>(
  1467. Expression.Call(
  1468. null,
  1469. #if CRIPPLED_REFLECTION
  1470. InfoOf(() => QueryableEx.Do<TSource>(default(IQueryable<TSource>), default(Expression<Action<TSource>>), default(Expression<Action<Exception>>), default(Expression<Action>))),
  1471. #else
  1472. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1473. #endif
  1474. source.Expression,
  1475. onNext,
  1476. onError,
  1477. onCompleted
  1478. )
  1479. );
  1480. }
  1481. #pragma warning disable 1591
  1482. [EditorBrowsable(EditorBrowsableState.Never)]
  1483. public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
  1484. {
  1485. return EnumerableEx.Do(source, onNext, onError, onCompleted);
  1486. }
  1487. #pragma warning restore 1591
  1488. /// <summary>
  1489. /// Lazily invokes observer methods for each value in the sequence, and upon successful or exceptional termination.
  1490. /// </summary>
  1491. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1492. /// <param name="source">Source sequence.</param>
  1493. /// <param name="observer">Observer to invoke notification calls on.</param>
  1494. /// <returns>Sequence exhibiting the side-effects of observer method invocation upon enumeration.</returns>
  1495. public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, IObserver<TSource> observer)
  1496. {
  1497. if (source == null)
  1498. throw new ArgumentNullException(nameof(source));
  1499. if (observer == null)
  1500. throw new ArgumentNullException(nameof(observer));
  1501. return source.Provider.CreateQuery<TSource>(
  1502. Expression.Call(
  1503. null,
  1504. #if CRIPPLED_REFLECTION
  1505. InfoOf(() => QueryableEx.Do<TSource>(default(IQueryable<TSource>), default(IObserver<TSource>))),
  1506. #else
  1507. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1508. #endif
  1509. source.Expression,
  1510. Expression.Constant(observer, typeof(IObserver<TSource>))
  1511. )
  1512. );
  1513. }
  1514. #pragma warning disable 1591
  1515. [EditorBrowsable(EditorBrowsableState.Never)]
  1516. public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, IObserver<TSource> observer)
  1517. {
  1518. return EnumerableEx.Do(source, observer);
  1519. }
  1520. #pragma warning restore 1591
  1521. /// <summary>
  1522. /// Generates a sequence of non-overlapping adjacent buffers over the source sequence.
  1523. /// </summary>
  1524. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1525. /// <param name="source">Source sequence.</param>
  1526. /// <param name="count">Number of elements for allocated buffers.</param>
  1527. /// <returns>Sequence of buffers containing source sequence elements.</returns>
  1528. public static IQueryable<IList<TSource>> Buffer<TSource>(this IQueryable<TSource> source, int count)
  1529. {
  1530. if (source == null)
  1531. throw new ArgumentNullException(nameof(source));
  1532. return source.Provider.CreateQuery<IList<TSource>>(
  1533. Expression.Call(
  1534. null,
  1535. #if CRIPPLED_REFLECTION
  1536. InfoOf(() => QueryableEx.Buffer<TSource>(default(IQueryable<TSource>), default(int))),
  1537. #else
  1538. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1539. #endif
  1540. source.Expression,
  1541. Expression.Constant(count, typeof(int))
  1542. )
  1543. );
  1544. }
  1545. #pragma warning disable 1591
  1546. [EditorBrowsable(EditorBrowsableState.Never)]
  1547. public static IEnumerable<IList<TSource>> Buffer<TSource>(IEnumerable<TSource> source, int count)
  1548. {
  1549. return EnumerableEx.Buffer(source, count);
  1550. }
  1551. #pragma warning restore 1591
  1552. /// <summary>
  1553. /// Generates a sequence of buffers over the source sequence, with specified length and possible overlap.
  1554. /// </summary>
  1555. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1556. /// <param name="source">Source sequence.</param>
  1557. /// <param name="count">Number of elements for allocated buffers.</param>
  1558. /// <param name="skip">Number of elements to skip between the start of consecutive buffers.</param>
  1559. /// <returns>Sequence of buffers containing source sequence elements.</returns>
  1560. public static IQueryable<IList<TSource>> Buffer<TSource>(this IQueryable<TSource> source, int count, int skip)
  1561. {
  1562. if (source == null)
  1563. throw new ArgumentNullException(nameof(source));
  1564. return source.Provider.CreateQuery<IList<TSource>>(
  1565. Expression.Call(
  1566. null,
  1567. #if CRIPPLED_REFLECTION
  1568. InfoOf(() => QueryableEx.Buffer<TSource>(default(IQueryable<TSource>), default(int), default(int))),
  1569. #else
  1570. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1571. #endif
  1572. source.Expression,
  1573. Expression.Constant(count, typeof(int)),
  1574. Expression.Constant(skip, typeof(int))
  1575. )
  1576. );
  1577. }
  1578. #pragma warning disable 1591
  1579. [EditorBrowsable(EditorBrowsableState.Never)]
  1580. public static IEnumerable<IList<TSource>> Buffer<TSource>(IEnumerable<TSource> source, int count, int skip)
  1581. {
  1582. return EnumerableEx.Buffer(source, count, skip);
  1583. }
  1584. #pragma warning restore 1591
  1585. /// <summary>
  1586. /// Ignores all elements in the source sequence.
  1587. /// </summary>
  1588. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1589. /// <param name="source">Source sequence.</param>
  1590. /// <returns>Source sequence without its elements.</returns>
  1591. public static IQueryable<TSource> IgnoreElements<TSource>(this IQueryable<TSource> source)
  1592. {
  1593. if (source == null)
  1594. throw new ArgumentNullException(nameof(source));
  1595. return source.Provider.CreateQuery<TSource>(
  1596. Expression.Call(
  1597. null,
  1598. #if CRIPPLED_REFLECTION
  1599. InfoOf(() => QueryableEx.IgnoreElements<TSource>(default(IQueryable<TSource>))),
  1600. #else
  1601. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1602. #endif
  1603. source.Expression
  1604. )
  1605. );
  1606. }
  1607. #pragma warning disable 1591
  1608. [EditorBrowsable(EditorBrowsableState.Never)]
  1609. public static IEnumerable<TSource> IgnoreElements<TSource>(IEnumerable<TSource> source)
  1610. {
  1611. return EnumerableEx.IgnoreElements(source);
  1612. }
  1613. #pragma warning restore 1591
  1614. /// <summary>
  1615. /// Returns elements with a distinct key value by using the default equality comparer to compare key values.
  1616. /// </summary>
  1617. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1618. /// <typeparam name="TKey">Key type.</typeparam>
  1619. /// <param name="source">Source sequence.</param>
  1620. /// <param name="keySelector">Key selector.</param>
  1621. /// <returns>Sequence that contains the elements from the source sequence with distinct key values.</returns>
  1622. public static IQueryable<TSource> Distinct<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  1623. {
  1624. if (source == null)
  1625. throw new ArgumentNullException(nameof(source));
  1626. if (keySelector == null)
  1627. throw new ArgumentNullException(nameof(keySelector));
  1628. return source.Provider.CreateQuery<TSource>(
  1629. Expression.Call(
  1630. null,
  1631. #if CRIPPLED_REFLECTION
  1632. InfoOf(() => QueryableEx.Distinct<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>))),
  1633. #else
  1634. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  1635. #endif
  1636. source.Expression,
  1637. keySelector
  1638. )
  1639. );
  1640. }
  1641. #pragma warning disable 1591
  1642. [EditorBrowsable(EditorBrowsableState.Never)]
  1643. public static IEnumerable<TSource> Distinct<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
  1644. {
  1645. return EnumerableEx.Distinct(source, keySelector);
  1646. }
  1647. #pragma warning restore 1591
  1648. /// <summary>
  1649. /// Returns elements with a distinct key value by using the specified equality comparer to compare key values.
  1650. /// </summary>
  1651. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1652. /// <typeparam name="TKey">Key type.</typeparam>
  1653. /// <param name="source">Source sequence.</param>
  1654. /// <param name="keySelector">Key selector.</param>
  1655. /// <param name="comparer">Comparer used to compare key values.</param>
  1656. /// <returns>Sequence that contains the elements from the source sequence with distinct key values.</returns>
  1657. public static IQueryable<TSource> Distinct<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
  1658. {
  1659. if (source == null)
  1660. throw new ArgumentNullException(nameof(source));
  1661. if (keySelector == null)
  1662. throw new ArgumentNullException(nameof(keySelector));
  1663. if (comparer == null)
  1664. throw new ArgumentNullException(nameof(comparer));
  1665. return source.Provider.CreateQuery<TSource>(
  1666. Expression.Call(
  1667. null,
  1668. #if CRIPPLED_REFLECTION
  1669. InfoOf(() => QueryableEx.Distinct<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>), default(IEqualityComparer<TKey>))),
  1670. #else
  1671. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  1672. #endif
  1673. source.Expression,
  1674. keySelector,
  1675. Expression.Constant(comparer, typeof(IEqualityComparer<TKey>))
  1676. )
  1677. );
  1678. }
  1679. #pragma warning disable 1591
  1680. [EditorBrowsable(EditorBrowsableState.Never)]
  1681. public static IEnumerable<TSource> Distinct<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
  1682. {
  1683. return EnumerableEx.Distinct(source, keySelector, comparer);
  1684. }
  1685. #pragma warning restore 1591
  1686. /// <summary>
  1687. /// Returns consecutive distinct elements by using the default equality comparer to compare values.
  1688. /// </summary>
  1689. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1690. /// <param name="source">Source sequence.</param>
  1691. /// <returns>Sequence without adjacent non-distinct elements.</returns>
  1692. public static IQueryable<TSource> DistinctUntilChanged<TSource>(this IQueryable<TSource> source)
  1693. {
  1694. if (source == null)
  1695. throw new ArgumentNullException(nameof(source));
  1696. return source.Provider.CreateQuery<TSource>(
  1697. Expression.Call(
  1698. null,
  1699. #if CRIPPLED_REFLECTION
  1700. InfoOf(() => QueryableEx.DistinctUntilChanged<TSource>(default(IQueryable<TSource>))),
  1701. #else
  1702. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1703. #endif
  1704. source.Expression
  1705. )
  1706. );
  1707. }
  1708. #pragma warning disable 1591
  1709. [EditorBrowsable(EditorBrowsableState.Never)]
  1710. public static IEnumerable<TSource> DistinctUntilChanged<TSource>(IEnumerable<TSource> source)
  1711. {
  1712. return EnumerableEx.DistinctUntilChanged(source);
  1713. }
  1714. #pragma warning restore 1591
  1715. /// <summary>
  1716. /// Returns consecutive distinct elements by using the specified equality comparer to compare values.
  1717. /// </summary>
  1718. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1719. /// <param name="source">Source sequence.</param>
  1720. /// <param name="comparer">Comparer used to compare values.</param>
  1721. /// <returns>Sequence without adjacent non-distinct elements.</returns>
  1722. public static IQueryable<TSource> DistinctUntilChanged<TSource>(this IQueryable<TSource> source, IEqualityComparer<TSource> comparer)
  1723. {
  1724. if (source == null)
  1725. throw new ArgumentNullException(nameof(source));
  1726. if (comparer == null)
  1727. throw new ArgumentNullException(nameof(comparer));
  1728. return source.Provider.CreateQuery<TSource>(
  1729. Expression.Call(
  1730. null,
  1731. #if CRIPPLED_REFLECTION
  1732. InfoOf(() => QueryableEx.DistinctUntilChanged<TSource>(default(IQueryable<TSource>), default(IEqualityComparer<TSource>))),
  1733. #else
  1734. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1735. #endif
  1736. source.Expression,
  1737. Expression.Constant(comparer, typeof(IEqualityComparer<TSource>))
  1738. )
  1739. );
  1740. }
  1741. #pragma warning disable 1591
  1742. [EditorBrowsable(EditorBrowsableState.Never)]
  1743. public static IEnumerable<TSource> DistinctUntilChanged<TSource>(IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
  1744. {
  1745. return EnumerableEx.DistinctUntilChanged(source, comparer);
  1746. }
  1747. #pragma warning restore 1591
  1748. /// <summary>
  1749. /// Returns consecutive distinct elements based on a key value by using the specified equality comparer to compare key values.
  1750. /// </summary>
  1751. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1752. /// <typeparam name="TKey">Key type.</typeparam>
  1753. /// <param name="source">Source sequence.</param>
  1754. /// <param name="keySelector">Key selector.</param>
  1755. /// <returns>Sequence without adjacent non-distinct elements.</returns>
  1756. public static IQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
  1757. {
  1758. if (source == null)
  1759. throw new ArgumentNullException(nameof(source));
  1760. if (keySelector == null)
  1761. throw new ArgumentNullException(nameof(keySelector));
  1762. return source.Provider.CreateQuery<TSource>(
  1763. Expression.Call(
  1764. null,
  1765. #if CRIPPLED_REFLECTION
  1766. InfoOf(() => QueryableEx.DistinctUntilChanged<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>))),
  1767. #else
  1768. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  1769. #endif
  1770. source.Expression,
  1771. keySelector
  1772. )
  1773. );
  1774. }
  1775. #pragma warning disable 1591
  1776. [EditorBrowsable(EditorBrowsableState.Never)]
  1777. public static IEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
  1778. {
  1779. return EnumerableEx.DistinctUntilChanged(source, keySelector);
  1780. }
  1781. #pragma warning restore 1591
  1782. /// <summary>
  1783. /// Returns consecutive distinct elements based on a key value by using the specified equality comparer to compare key values.
  1784. /// </summary>
  1785. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1786. /// <typeparam name="TKey">Key type.</typeparam>
  1787. /// <param name="source">Source sequence.</param>
  1788. /// <param name="keySelector">Key selector.</param>
  1789. /// <param name="comparer">Comparer used to compare key values.</param>
  1790. /// <returns>Sequence without adjacent non-distinct elements.</returns>
  1791. public static IQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
  1792. {
  1793. if (source == null)
  1794. throw new ArgumentNullException(nameof(source));
  1795. if (keySelector == null)
  1796. throw new ArgumentNullException(nameof(keySelector));
  1797. if (comparer == null)
  1798. throw new ArgumentNullException(nameof(comparer));
  1799. return source.Provider.CreateQuery<TSource>(
  1800. Expression.Call(
  1801. null,
  1802. #if CRIPPLED_REFLECTION
  1803. InfoOf(() => QueryableEx.DistinctUntilChanged<TSource, TKey>(default(IQueryable<TSource>), default(Expression<Func<TSource, TKey>>), default(IEqualityComparer<TKey>))),
  1804. #else
  1805. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
  1806. #endif
  1807. source.Expression,
  1808. keySelector,
  1809. Expression.Constant(comparer, typeof(IEqualityComparer<TKey>))
  1810. )
  1811. );
  1812. }
  1813. #pragma warning disable 1591
  1814. [EditorBrowsable(EditorBrowsableState.Never)]
  1815. public static IEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
  1816. {
  1817. return EnumerableEx.DistinctUntilChanged(source, keySelector, comparer);
  1818. }
  1819. #pragma warning restore 1591
  1820. /// <summary>
  1821. /// Expands the sequence by recursively applying a selector function.
  1822. /// </summary>
  1823. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1824. /// <param name="source">Source sequence.</param>
  1825. /// <param name="selector">Selector function to retrieve the next sequence to expand.</param>
  1826. /// <returns>Sequence with results from the recursive expansion of the source sequence.</returns>
  1827. public static IQueryable<TSource> Expand<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TSource>>> selector)
  1828. {
  1829. if (source == null)
  1830. throw new ArgumentNullException(nameof(source));
  1831. if (selector == null)
  1832. throw new ArgumentNullException(nameof(selector));
  1833. return source.Provider.CreateQuery<TSource>(
  1834. Expression.Call(
  1835. null,
  1836. #if CRIPPLED_REFLECTION
  1837. InfoOf(() => QueryableEx.Expand<TSource>(default(IQueryable<TSource>), default(Expression<Func<TSource, IEnumerable<TSource>>>))),
  1838. #else
  1839. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1840. #endif
  1841. source.Expression,
  1842. selector
  1843. )
  1844. );
  1845. }
  1846. #pragma warning disable 1591
  1847. [EditorBrowsable(EditorBrowsableState.Never)]
  1848. public static IEnumerable<TSource> Expand<TSource>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TSource>> selector)
  1849. {
  1850. return EnumerableEx.Expand(source, selector);
  1851. }
  1852. #pragma warning restore 1591
  1853. /// <summary>
  1854. /// Returns the source sequence prefixed with the specified value.
  1855. /// </summary>
  1856. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1857. /// <param name="source">Source sequence.</param>
  1858. /// <param name="values">Values to prefix the sequence with.</param>
  1859. /// <returns>Sequence starting with the specified prefix value, followed by the source sequence.</returns>
  1860. public static IQueryable<TSource> StartWith<TSource>(this IQueryable<TSource> source, params TSource[] values)
  1861. {
  1862. if (source == null)
  1863. throw new ArgumentNullException(nameof(source));
  1864. return source.Provider.CreateQuery<TSource>(
  1865. Expression.Call(
  1866. null,
  1867. #if CRIPPLED_REFLECTION
  1868. InfoOf(() => QueryableEx.StartWith<TSource>(default(IQueryable<TSource>), default(TSource[]))),
  1869. #else
  1870. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1871. #endif
  1872. source.Expression,
  1873. Expression.Constant(values, typeof(TSource[]))
  1874. )
  1875. );
  1876. }
  1877. #pragma warning disable 1591
  1878. [EditorBrowsable(EditorBrowsableState.Never)]
  1879. public static IEnumerable<TSource> StartWith<TSource>(IEnumerable<TSource> source, params TSource[] values)
  1880. {
  1881. return EnumerableEx.StartWith(source, values);
  1882. }
  1883. #pragma warning restore 1591
  1884. /// <summary>
  1885. /// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.
  1886. /// </summary>
  1887. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1888. /// <typeparam name="TAccumulate">Accumulation type.</typeparam>
  1889. /// <param name="source">Source sequence.</param>
  1890. /// <param name="seed">Accumulator seed value.</param>
  1891. /// <param name="accumulator">Accumulation function to apply to the current accumulation value and each element of the sequence.</param>
  1892. /// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>
  1893. public static IQueryable<TAccumulate> Scan<TSource, TAccumulate>(this IQueryable<TSource> source, TAccumulate seed, Expression<Func<TAccumulate, TSource, TAccumulate>> accumulator)
  1894. {
  1895. if (source == null)
  1896. throw new ArgumentNullException(nameof(source));
  1897. if (accumulator == null)
  1898. throw new ArgumentNullException(nameof(accumulator));
  1899. return source.Provider.CreateQuery<TAccumulate>(
  1900. Expression.Call(
  1901. null,
  1902. #if CRIPPLED_REFLECTION
  1903. InfoOf(() => QueryableEx.Scan<TSource, TAccumulate>(default(IQueryable<TSource>), default(TAccumulate), default(Expression<Func<TAccumulate, TSource, TAccumulate>>))),
  1904. #else
  1905. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TAccumulate)),
  1906. #endif
  1907. source.Expression,
  1908. Expression.Constant(seed, typeof(TAccumulate)),
  1909. accumulator
  1910. )
  1911. );
  1912. }
  1913. #pragma warning disable 1591
  1914. [EditorBrowsable(EditorBrowsableState.Never)]
  1915. public static IEnumerable<TAccumulate> Scan<TSource, TAccumulate>(IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
  1916. {
  1917. return EnumerableEx.Scan(source, seed, accumulator);
  1918. }
  1919. #pragma warning restore 1591
  1920. /// <summary>
  1921. /// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.
  1922. /// </summary>
  1923. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1924. /// <param name="source">Source sequence.</param>
  1925. /// <param name="accumulator">Accumulation function to apply to the current accumulation value and each element of the sequence.</param>
  1926. /// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>
  1927. public static IQueryable<TSource> Scan<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, TSource, TSource>> accumulator)
  1928. {
  1929. if (source == null)
  1930. throw new ArgumentNullException(nameof(source));
  1931. if (accumulator == null)
  1932. throw new ArgumentNullException(nameof(accumulator));
  1933. return source.Provider.CreateQuery<TSource>(
  1934. Expression.Call(
  1935. null,
  1936. #if CRIPPLED_REFLECTION
  1937. InfoOf(() => QueryableEx.Scan<TSource>(default(IQueryable<TSource>), default(Expression<Func<TSource, TSource, TSource>>))),
  1938. #else
  1939. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1940. #endif
  1941. source.Expression,
  1942. accumulator
  1943. )
  1944. );
  1945. }
  1946. #pragma warning disable 1591
  1947. [EditorBrowsable(EditorBrowsableState.Never)]
  1948. public static IEnumerable<TSource> Scan<TSource>(IEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator)
  1949. {
  1950. return EnumerableEx.Scan(source, accumulator);
  1951. }
  1952. #pragma warning restore 1591
  1953. /// <summary>
  1954. /// Returns a specified number of contiguous elements from the end of the sequence.
  1955. /// </summary>
  1956. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1957. /// <param name="source">Source sequence.</param>
  1958. /// <param name="count">The number of elements to take from the end of the sequence.</param>
  1959. /// <returns>Sequence with the specified number of elements counting from the end of the source sequence.</returns>
  1960. public static IQueryable<TSource> TakeLast<TSource>(this IQueryable<TSource> source, int count)
  1961. {
  1962. if (source == null)
  1963. throw new ArgumentNullException(nameof(source));
  1964. return source.Provider.CreateQuery<TSource>(
  1965. Expression.Call(
  1966. null,
  1967. #if CRIPPLED_REFLECTION
  1968. InfoOf(() => QueryableEx.TakeLast<TSource>(default(IQueryable<TSource>), default(int))),
  1969. #else
  1970. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  1971. #endif
  1972. source.Expression,
  1973. Expression.Constant(count, typeof(int))
  1974. )
  1975. );
  1976. }
  1977. #pragma warning disable 1591
  1978. [EditorBrowsable(EditorBrowsableState.Never)]
  1979. public static IEnumerable<TSource> TakeLast<TSource>(IEnumerable<TSource> source, int count)
  1980. {
  1981. return EnumerableEx.TakeLast(source, count);
  1982. }
  1983. #pragma warning restore 1591
  1984. /// <summary>
  1985. /// Bypasses a specified number of contiguous elements from the end of the sequence and returns the remaining elements.
  1986. /// </summary>
  1987. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  1988. /// <param name="source">Source sequence.</param>
  1989. /// <param name="count">The number of elements to skip from the end of the sequence before returning the remaining elements.</param>
  1990. /// <returns>Sequence bypassing the specified number of elements counting from the end of the source sequence.</returns>
  1991. public static IQueryable<TSource> SkipLast<TSource>(this IQueryable<TSource> source, int count)
  1992. {
  1993. if (source == null)
  1994. throw new ArgumentNullException(nameof(source));
  1995. return source.Provider.CreateQuery<TSource>(
  1996. Expression.Call(
  1997. null,
  1998. #if CRIPPLED_REFLECTION
  1999. InfoOf(() => QueryableEx.SkipLast<TSource>(default(IQueryable<TSource>), default(int))),
  2000. #else
  2001. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  2002. #endif
  2003. source.Expression,
  2004. Expression.Constant(count, typeof(int))
  2005. )
  2006. );
  2007. }
  2008. #pragma warning disable 1591
  2009. [EditorBrowsable(EditorBrowsableState.Never)]
  2010. public static IEnumerable<TSource> SkipLast<TSource>(IEnumerable<TSource> source, int count)
  2011. {
  2012. return EnumerableEx.SkipLast(source, count);
  2013. }
  2014. #pragma warning restore 1591
  2015. /// <summary>
  2016. /// Repeats and concatenates the source sequence infinitely.
  2017. /// </summary>
  2018. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  2019. /// <param name="source">Source sequence.</param>
  2020. /// <returns>Sequence obtained by concatenating the source sequence to itself infinitely.</returns>
  2021. public static IQueryable<TSource> Repeat<TSource>(this IQueryable<TSource> source)
  2022. {
  2023. if (source == null)
  2024. throw new ArgumentNullException(nameof(source));
  2025. return source.Provider.CreateQuery<TSource>(
  2026. Expression.Call(
  2027. null,
  2028. #if CRIPPLED_REFLECTION
  2029. InfoOf(() => QueryableEx.Repeat<TSource>(default(IQueryable<TSource>))),
  2030. #else
  2031. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  2032. #endif
  2033. source.Expression
  2034. )
  2035. );
  2036. }
  2037. #pragma warning disable 1591
  2038. [EditorBrowsable(EditorBrowsableState.Never)]
  2039. public static IEnumerable<TSource> Repeat<TSource>(IEnumerable<TSource> source)
  2040. {
  2041. return EnumerableEx.Repeat(source);
  2042. }
  2043. #pragma warning restore 1591
  2044. /// <summary>
  2045. /// Repeats and concatenates the source sequence the given number of times.
  2046. /// </summary>
  2047. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  2048. /// <param name="source">Source sequence.</param>
  2049. /// <param name="count">Number of times to repeat the source sequence.</param>
  2050. /// <returns>Sequence obtained by concatenating the source sequence to itself the specified number of times.</returns>
  2051. public static IQueryable<TSource> Repeat<TSource>(this IQueryable<TSource> source, int count)
  2052. {
  2053. if (source == null)
  2054. throw new ArgumentNullException(nameof(source));
  2055. return source.Provider.CreateQuery<TSource>(
  2056. Expression.Call(
  2057. null,
  2058. #if CRIPPLED_REFLECTION
  2059. InfoOf(() => QueryableEx.Repeat<TSource>(default(IQueryable<TSource>), default(int))),
  2060. #else
  2061. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
  2062. #endif
  2063. source.Expression,
  2064. Expression.Constant(count, typeof(int))
  2065. )
  2066. );
  2067. }
  2068. #pragma warning disable 1591
  2069. [EditorBrowsable(EditorBrowsableState.Never)]
  2070. public static IEnumerable<TSource> Repeat<TSource>(IEnumerable<TSource> source, int count)
  2071. {
  2072. return EnumerableEx.Repeat(source, count);
  2073. }
  2074. #pragma warning restore 1591
  2075. /// <summary>
  2076. /// Returns a sequence with no elements.
  2077. /// </summary>
  2078. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  2079. /// <param name="provider">Query provider.</param>
  2080. /// <returns>Sequence with no elements.</returns>
  2081. public static IQueryable<TResult> Empty<TResult>(this IQueryProvider provider)
  2082. {
  2083. if (provider == null)
  2084. throw new ArgumentNullException(nameof(provider));
  2085. return provider.CreateQuery<TResult>(
  2086. Expression.Call(
  2087. null,
  2088. #if CRIPPLED_REFLECTION
  2089. InfoOf(() => QueryableEx.Empty<TResult>(default(IQueryProvider))),
  2090. #else
  2091. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  2092. #endif
  2093. Expression.Constant(provider, typeof(IQueryProvider))
  2094. )
  2095. );
  2096. }
  2097. #pragma warning disable 1591
  2098. [EditorBrowsable(EditorBrowsableState.Never)]
  2099. public static /*!*/IQueryable<TResult> Empty<TResult>()
  2100. {
  2101. return Enumerable.Empty<TResult>().AsQueryable();
  2102. }
  2103. #pragma warning restore 1591
  2104. /// <summary>
  2105. /// Generates a sequence of integral numbers within a specified range.
  2106. /// </summary>
  2107. /// <param name="provider">Query provider.</param>
  2108. /// <param name="start">The value of the first integer in the sequence.</param>
  2109. /// <param name="count">The number of sequential integers to generate.</param>
  2110. /// <returns>Sequence that contains a range of sequential integral numbers.</returns>
  2111. public static IQueryable<int> Range(this IQueryProvider provider, int start, int count)
  2112. {
  2113. if (provider == null)
  2114. throw new ArgumentNullException(nameof(provider));
  2115. return provider.CreateQuery<int>(
  2116. Expression.Call(
  2117. null,
  2118. #if CRIPPLED_REFLECTION
  2119. InfoOf(() => QueryableEx.Range(default(IQueryProvider), default(int), default(int))),
  2120. #else
  2121. (MethodInfo)MethodInfo.GetCurrentMethod(),
  2122. #endif
  2123. Expression.Constant(provider, typeof(IQueryProvider)),
  2124. Expression.Constant(start, typeof(int)),
  2125. Expression.Constant(count, typeof(int))
  2126. )
  2127. );
  2128. }
  2129. #pragma warning disable 1591
  2130. [EditorBrowsable(EditorBrowsableState.Never)]
  2131. public static /*!*/IQueryable<int> Range(int start, int count)
  2132. {
  2133. return Enumerable.Range(start, count).AsQueryable();
  2134. }
  2135. #pragma warning restore 1591
  2136. /// <summary>
  2137. /// Generates a sequence that contains one repeated value.
  2138. /// </summary>
  2139. /// <typeparam name="TResult">Result sequence element type.</typeparam>
  2140. /// <param name="provider">Query provider.</param>
  2141. /// <param name="element">The value to be repeated.</param>
  2142. /// <param name="count">The number of times to repeat the value in the generated sequence.</param>
  2143. /// <returns>Sequence that contains a repeated value.</returns>
  2144. public static IQueryable<TResult> Repeat<TResult>(this IQueryProvider provider, TResult element, int count)
  2145. {
  2146. if (provider == null)
  2147. throw new ArgumentNullException(nameof(provider));
  2148. return provider.CreateQuery<TResult>(
  2149. Expression.Call(
  2150. null,
  2151. #if CRIPPLED_REFLECTION
  2152. InfoOf(() => QueryableEx.Repeat<TResult>(default(IQueryProvider), default(TResult), default(int))),
  2153. #else
  2154. ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
  2155. #endif
  2156. Expression.Constant(provider, typeof(IQueryProvider)),
  2157. Expression.Constant(element, typeof(TResult)),
  2158. Expression.Constant(count, typeof(int))
  2159. )
  2160. );
  2161. }
  2162. #pragma warning disable 1591
  2163. [EditorBrowsable(EditorBrowsableState.Never)]
  2164. public static /*!*/IQueryable<TResult> Repeat<TResult>(TResult element, int count)
  2165. {
  2166. return EnumerableEx.Repeat<TResult>(element, count).AsQueryable();
  2167. }
  2168. #pragma warning restore 1591
  2169. }
  2170. }