QueryableEx.Generated.cs 110 KB

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