Expression.cs 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. //
  2. // Expression.cs
  3. //
  4. // Author:
  5. // Jb Evain ([email protected])
  6. // Miguel de Icaza ([email protected])
  7. //
  8. // (C) 2008 Novell, Inc. (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.Reflection;
  33. namespace System.Linq.Expressions {
  34. public abstract class Expression {
  35. ExpressionType node_type;
  36. Type type;
  37. public ExpressionType NodeType {
  38. get { return node_type; }
  39. }
  40. public Type Type {
  41. get { return type; }
  42. }
  43. // TODO: remove when all Expression subtypes
  44. // have their constructor implemented
  45. protected Expression ()
  46. {
  47. }
  48. protected Expression (ExpressionType node_type, Type type)
  49. {
  50. this.node_type = node_type;
  51. this.type = type;
  52. }
  53. public override string ToString ()
  54. {
  55. return ExpressionPrinter.ToString (this);
  56. }
  57. #region Binary Expressions
  58. static void BinaryCoreCheck (Expression left, Expression right)
  59. {
  60. if (left == null)
  61. throw new ArgumentNullException ("left");
  62. if (right == null)
  63. throw new ArgumentNullException ("right");
  64. if (left.Type != right.Type)
  65. throw new InvalidOperationException ("Both expressions must have the same type");
  66. }
  67. static BinaryExpression MakeSimpleBinary (ExpressionType et, Expression left, Expression right, MethodInfo method)
  68. {
  69. return new BinaryExpression (et, left.Type, left, right, method);
  70. }
  71. static BinaryExpression MakeSimpleBinary (ExpressionType et, Type result, Expression left, Expression right, MethodInfo method)
  72. {
  73. return new BinaryExpression (et, result, left, right, method);
  74. }
  75. static BinaryExpression MakeBoolBinary (ExpressionType et, Expression left, Expression right, bool liftToNull, MethodInfo method)
  76. {
  77. return new BinaryExpression (et, typeof (bool), left, right, method);
  78. }
  79. //
  80. // Arithmetic
  81. //
  82. public static BinaryExpression Add (Expression left, Expression right)
  83. {
  84. return Add (left, right, null);
  85. }
  86. public static BinaryExpression Add (Expression left, Expression right, MethodInfo method)
  87. {
  88. BinaryCoreCheck (left, right);
  89. return MakeSimpleBinary (ExpressionType.Add, left, right, method);
  90. }
  91. public static BinaryExpression AddChecked (Expression left, Expression right)
  92. {
  93. return AddChecked (left, right, null);
  94. }
  95. public static BinaryExpression AddChecked (Expression left, Expression right, MethodInfo method)
  96. {
  97. return MakeSimpleBinary (ExpressionType.AddChecked, left, right, method);
  98. }
  99. public static BinaryExpression Subtract (Expression left, Expression right)
  100. {
  101. return Subtract (left, right, null);
  102. }
  103. public static BinaryExpression Subtract (Expression left, Expression right, MethodInfo method)
  104. {
  105. BinaryCoreCheck (left, right);
  106. return MakeSimpleBinary (ExpressionType.Subtract, left, right, method);
  107. }
  108. public static BinaryExpression SubtractChecked (Expression left, Expression right)
  109. {
  110. return SubtractChecked (left, right, null);
  111. }
  112. public static BinaryExpression SubtractChecked (Expression left, Expression right, MethodInfo method)
  113. {
  114. BinaryCoreCheck (left, right);
  115. return MakeSimpleBinary (ExpressionType.SubtractChecked, left, right, method);
  116. }
  117. public static BinaryExpression Modulo (Expression left, Expression right)
  118. {
  119. return Modulo (left, right, null);
  120. }
  121. public static BinaryExpression Modulo (Expression left, Expression right, MethodInfo method)
  122. {
  123. BinaryCoreCheck (left, right);
  124. return MakeSimpleBinary (ExpressionType.Modulo, left, right, method);
  125. }
  126. public static BinaryExpression Multiply (Expression left, Expression right)
  127. {
  128. return Multiply (left, right, null);
  129. }
  130. public static BinaryExpression Multiply (Expression left, Expression right, MethodInfo method)
  131. {
  132. BinaryCoreCheck (left, right);
  133. return MakeSimpleBinary (ExpressionType.Multiply, left, right, method);
  134. }
  135. public static BinaryExpression MultiplyChecked (Expression left, Expression right)
  136. {
  137. return MultiplyChecked (left, right, null);
  138. }
  139. public static BinaryExpression MultiplyChecked (Expression left, Expression right, MethodInfo method)
  140. {
  141. BinaryCoreCheck (left, right);
  142. return MakeSimpleBinary (ExpressionType.MultiplyChecked, left, right, method);
  143. }
  144. public static BinaryExpression Divide (Expression left, Expression right)
  145. {
  146. return Divide (left, right, null);
  147. }
  148. public static BinaryExpression Divide (Expression left, Expression right, MethodInfo method)
  149. {
  150. BinaryCoreCheck (left, right);
  151. return MakeSimpleBinary (ExpressionType.Divide, left, right, method);
  152. }
  153. public static BinaryExpression Power (Expression left, Expression right)
  154. {
  155. return Power (left, right, null);
  156. }
  157. public static BinaryExpression Power (Expression left, Expression right, MethodInfo method)
  158. {
  159. BinaryCoreCheck (left, right);
  160. if (left.Type != typeof (double))
  161. throw new InvalidOperationException ("Power only supports double arguments");
  162. return MakeSimpleBinary (ExpressionType.Power, left, right, method);
  163. }
  164. //
  165. // Bitwise
  166. //
  167. static bool IsInt (Type t)
  168. {
  169. return
  170. t == typeof (int) || t == typeof (uint) ||
  171. t == typeof (short) || t == typeof (ushort) ||
  172. t == typeof (long) || t == typeof (ulong);
  173. }
  174. public static BinaryExpression And (Expression left, Expression right)
  175. {
  176. return And (left, right, null);
  177. }
  178. public static BinaryExpression And (Expression left, Expression right, MethodInfo method)
  179. {
  180. BinaryCoreCheck (left, right);
  181. if (left.Type == typeof (bool) || IsInt (left.Type))
  182. return MakeSimpleBinary (ExpressionType.And, left, right, method);
  183. throw new InvalidOperationException ("Only integral or bool types allowed");
  184. }
  185. public static BinaryExpression Or (Expression left, Expression right)
  186. {
  187. return Or (left, right, null);
  188. }
  189. public static BinaryExpression Or (Expression left, Expression right, MethodInfo method)
  190. {
  191. BinaryCoreCheck (left, right);
  192. if (left.Type == typeof (bool) || IsInt (left.Type))
  193. return MakeSimpleBinary (ExpressionType.Or, left, right, method);
  194. throw new InvalidOperationException ("Only integral or bool types allowed");
  195. }
  196. public static BinaryExpression ExclusiveOr (Expression left, Expression right)
  197. {
  198. return ExclusiveOr (left, right, null);
  199. }
  200. public static BinaryExpression ExclusiveOr (Expression left, Expression right, MethodInfo method)
  201. {
  202. BinaryCoreCheck (left, right);
  203. if (left.Type == typeof (bool) || IsInt (left.Type))
  204. return MakeSimpleBinary (ExpressionType.ExclusiveOr, left, right, method);
  205. throw new InvalidOperationException ("Only integral or bool types allowed");
  206. }
  207. public static BinaryExpression LeftShift (Expression left, Expression right)
  208. {
  209. return LeftShift (left, right, null);
  210. }
  211. public static BinaryExpression LeftShift (Expression left, Expression right, MethodInfo method)
  212. {
  213. BinaryCoreCheck (left, right);
  214. if (left.Type == typeof (int))
  215. return MakeSimpleBinary (ExpressionType.LeftShift, left, right, method);
  216. throw new InvalidOperationException ("Only int32 is allowed for shifts");
  217. }
  218. public static BinaryExpression RightShift (Expression left, Expression right)
  219. {
  220. return RightShift (left, right, null);
  221. }
  222. public static BinaryExpression RightShift (Expression left, Expression right, MethodInfo method)
  223. {
  224. BinaryCoreCheck (left, right);
  225. if (left.Type == typeof (int))
  226. return MakeSimpleBinary (ExpressionType.RightShift, left, right, method);
  227. throw new InvalidOperationException ("Only int32 is allowed for shifts");
  228. }
  229. //
  230. // Short-circuit
  231. //
  232. public static BinaryExpression AndAlso (Expression left, Expression right)
  233. {
  234. return AndAlso (left, right, null);
  235. }
  236. [MonoTODO]
  237. public static BinaryExpression AndAlso (Expression left, Expression right, MethodInfo method)
  238. {
  239. // This does not work with int, int pairs; Figure out when its valid
  240. throw new NotImplementedException ();
  241. }
  242. [MonoTODO]
  243. public static BinaryExpression OrElse (Expression left, Expression right)
  244. {
  245. throw new NotImplementedException ();
  246. }
  247. [MonoTODO]
  248. public static BinaryExpression OrElse (Expression left, Expression right, MethodInfo method)
  249. {
  250. throw new NotImplementedException ();
  251. }
  252. //
  253. // Comparison
  254. //
  255. public static BinaryExpression Equal (Expression left, Expression right)
  256. {
  257. return Equal (left, right, false, null);
  258. }
  259. public static BinaryExpression Equal (Expression left, Expression right, bool liftToNull, MethodInfo method)
  260. {
  261. BinaryCoreCheck (left, right);
  262. return MakeBoolBinary (ExpressionType.Equal, left, right, liftToNull, method);
  263. }
  264. public static BinaryExpression NotEqual (Expression left, Expression right)
  265. {
  266. return NotEqual (left, right, false, null);
  267. }
  268. public static BinaryExpression NotEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
  269. {
  270. BinaryCoreCheck (left, right);
  271. return MakeBoolBinary (ExpressionType.NotEqual, left, right, liftToNull, method);
  272. }
  273. public static BinaryExpression GreaterThan (Expression left, Expression right)
  274. {
  275. return GreaterThan (left, right, false, null);
  276. }
  277. public static BinaryExpression GreaterThan (Expression left, Expression right, bool liftToNull, MethodInfo method)
  278. {
  279. BinaryCoreCheck (left, right);
  280. return MakeBoolBinary (ExpressionType.GreaterThan, left, right, liftToNull, method);
  281. }
  282. public static BinaryExpression GreaterThanOrEqual (Expression left, Expression right)
  283. {
  284. return GreaterThanOrEqual (left, right, false, null);
  285. }
  286. public static BinaryExpression GreaterThanOrEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
  287. {
  288. BinaryCoreCheck (left, right);
  289. return MakeBoolBinary (ExpressionType.GreaterThanOrEqual, left, right, liftToNull, method);
  290. }
  291. public static BinaryExpression LessThan (Expression left, Expression right)
  292. {
  293. return LessThan (left, right, false, null);
  294. }
  295. public static BinaryExpression LessThan (Expression left, Expression right, bool liftToNull, MethodInfo method)
  296. {
  297. return MakeBoolBinary (ExpressionType.LessThan, left, right, liftToNull, method);
  298. }
  299. public static BinaryExpression LessThanOrEqual (Expression left, Expression right)
  300. {
  301. return LessThanOrEqual (left, right, false, null);
  302. }
  303. public static BinaryExpression LessThanOrEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
  304. {
  305. BinaryCoreCheck (left, right);
  306. return MakeBoolBinary (ExpressionType.LessThanOrEqual, left, right, liftToNull, method);
  307. }
  308. //
  309. // Miscelaneous
  310. //
  311. [MonoTODO]
  312. public static BinaryExpression ArrayIndex (Expression left, Expression index)
  313. {
  314. throw new NotImplementedException ();
  315. }
  316. public static BinaryExpression Coalesce (Expression left, Expression right)
  317. {
  318. return Coalesce (left, right, null);
  319. }
  320. [MonoTODO]
  321. public static BinaryExpression Coalesce (Expression left, Expression right, LambdaExpression conversion)
  322. {
  323. BinaryCoreCheck (left, right);
  324. throw new NotImplementedException ();
  325. }
  326. //
  327. // MakeBinary constructors
  328. //
  329. public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right)
  330. {
  331. return MakeBinary (binaryType, left, right, false, null);
  332. }
  333. public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right, bool liftToNull, MethodInfo method)
  334. {
  335. return MakeBinary (binaryType, left, right, liftToNull, method, null);
  336. }
  337. public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right, bool liftToNull, MethodInfo method, LambdaExpression conversion)
  338. {
  339. switch (binaryType) {
  340. case ExpressionType.Add:
  341. return Add (left, right, method);
  342. case ExpressionType.AddChecked:
  343. return AddChecked (left, right, method);
  344. case ExpressionType.AndAlso:
  345. return AndAlso (left, right);
  346. case ExpressionType.Coalesce:
  347. return Coalesce (left, right, conversion);
  348. case ExpressionType.Divide:
  349. return Divide (left, right, method);
  350. case ExpressionType.Equal:
  351. return Equal (left, right, liftToNull, method);
  352. case ExpressionType.ExclusiveOr:
  353. return ExclusiveOr (left, right, method);
  354. case ExpressionType.GreaterThan:
  355. return GreaterThan (left, right, liftToNull, method);
  356. case ExpressionType.GreaterThanOrEqual:
  357. return GreaterThanOrEqual (left, right, liftToNull, method);
  358. case ExpressionType.LeftShift:
  359. return LeftShift (left, right, method);
  360. case ExpressionType.LessThan:
  361. return LessThan (left, right, liftToNull, method);
  362. case ExpressionType.LessThanOrEqual:
  363. return LessThanOrEqual (left, right, liftToNull, method);
  364. case ExpressionType.Modulo:
  365. return Modulo (left, right, method);
  366. case ExpressionType.Multiply:
  367. return Multiply (left, right, method);
  368. case ExpressionType.MultiplyChecked:
  369. return MultiplyChecked (left, right, method);
  370. case ExpressionType.NotEqual:
  371. return NotEqual (left, right, liftToNull, method);
  372. case ExpressionType.OrElse:
  373. return OrElse (left, right);
  374. case ExpressionType.Power:
  375. return Power (left, right, method);
  376. case ExpressionType.RightShift:
  377. return RightShift (left, right, method);
  378. case ExpressionType.Subtract:
  379. return Subtract (left, right, method);
  380. case ExpressionType.SubtractChecked:
  381. return SubtractChecked (left, right, method);
  382. case ExpressionType.And:
  383. return And (left, right, method);
  384. case ExpressionType.Or:
  385. return Or (left, right, method);
  386. }
  387. throw new ArgumentException ("MakeBinary expect a binary node type");
  388. }
  389. #endregion
  390. [MonoTODO]
  391. public static MethodCallExpression ArrayIndex (Expression left, params Expression [] indexes)
  392. {
  393. throw new NotImplementedException ();
  394. }
  395. [MonoTODO]
  396. public static MethodCallExpression ArrayIndex (Expression left, IEnumerable<Expression> indexes)
  397. {
  398. throw new NotImplementedException ();
  399. }
  400. public static UnaryExpression ArrayLength (Expression array)
  401. {
  402. if (array == null)
  403. throw new ArgumentNullException ("array");
  404. if (!array.Type.IsArray)
  405. throw new ArgumentException ("The type of the expression must me Array");
  406. if (array.Type.GetArrayRank () != 1)
  407. throw new ArgumentException ("The array must be a single dimensional array");
  408. return new UnaryExpression (ExpressionType.ArrayLength, array, typeof (int));
  409. }
  410. [MonoTODO]
  411. public static MemberAssignment Bind (MemberInfo member, Expression expression)
  412. {
  413. throw new NotImplementedException ();
  414. }
  415. [MonoTODO]
  416. public static MemberAssignment Bind (MethodInfo propertyAccessor, Expression expression)
  417. {
  418. throw new NotImplementedException ();
  419. }
  420. [MonoTODO]
  421. public static MethodCallExpression Call (Expression instance, MethodInfo method)
  422. {
  423. throw new NotImplementedException ();
  424. }
  425. [MonoTODO]
  426. public static MethodCallExpression Call (MethodInfo method, params Expression [] arguments)
  427. {
  428. throw new NotImplementedException ();
  429. }
  430. [MonoTODO]
  431. public static MethodCallExpression Call (Expression instance, MethodInfo method, params Expression [] arguments)
  432. {
  433. throw new NotImplementedException ();
  434. }
  435. [MonoTODO]
  436. public static MethodCallExpression Call (Expression instance, MethodInfo method, IEnumerable<Expression> arguments)
  437. {
  438. throw new NotImplementedException ();
  439. }
  440. [MonoTODO]
  441. public static MethodCallExpression Call (Expression instance, string methodName, Type [] typeArguments, params Expression [] arguments)
  442. {
  443. throw new NotImplementedException ();
  444. }
  445. [MonoTODO]
  446. public static MethodCallExpression Call (Type type, string methodName, Type [] typeArguments, params Expression [] arguments)
  447. {
  448. throw new NotImplementedException ();
  449. }
  450. [MonoTODO]
  451. public static ConditionalExpression Condition (Expression test, Expression ifTrue, Expression ifFalse)
  452. {
  453. throw new NotImplementedException ();
  454. }
  455. public static ConstantExpression Constant (object value)
  456. {
  457. if (value == null)
  458. return new ConstantExpression (null, typeof (object));
  459. return Constant (value, value.GetType ());
  460. }
  461. public static ConstantExpression Constant (object value, Type type)
  462. {
  463. if (type == null)
  464. throw new ArgumentNullException ("type");
  465. //
  466. // value must be compatible with type, no conversions
  467. // are allowed
  468. //
  469. if (value == null){
  470. if (type.IsValueType && !IsNullable (type))
  471. throw new ArgumentException ();
  472. } else {
  473. if (!(type.IsValueType && IsNullable (type)) && value.GetType () != type)
  474. throw new ArgumentException ();
  475. }
  476. return new ConstantExpression (value, type);
  477. }
  478. [MonoTODO]
  479. public static UnaryExpression Convert (Expression expression, Type type)
  480. {
  481. throw new NotImplementedException ();
  482. }
  483. [MonoTODO]
  484. public static UnaryExpression Convert (Expression expression, Type type, MethodInfo method)
  485. {
  486. throw new NotImplementedException ();
  487. }
  488. [MonoTODO]
  489. public static UnaryExpression ConvertChecked (Expression expression, Type type)
  490. {
  491. throw new NotImplementedException ();
  492. }
  493. [MonoTODO]
  494. public static UnaryExpression ConvertChecked (Expression expression, Type type, MethodInfo method)
  495. {
  496. throw new NotImplementedException ();
  497. }
  498. [MonoTODO]
  499. public static ElementInit ElementInit (MethodInfo addMethod, params Expression [] arguments)
  500. {
  501. throw new NotImplementedException ();
  502. }
  503. [MonoTODO]
  504. public static ElementInit ElementInit (MethodInfo addMethod, IEnumerable<Expression> arguments)
  505. {
  506. throw new NotImplementedException ();
  507. }
  508. [MonoTODO]
  509. public static MemberExpression Field (Expression expression, FieldInfo field)
  510. {
  511. throw new NotImplementedException ();
  512. }
  513. [MonoTODO]
  514. public static MemberExpression Field (Expression expression, string fieldName)
  515. {
  516. throw new NotImplementedException ();
  517. }
  518. public static Type GetActionType (params Type [] typeArgs)
  519. {
  520. if (typeArgs == null)
  521. throw new ArgumentNullException ("typeArgs");
  522. if (typeArgs.Length > 4)
  523. throw new ArgumentException ("No Action type of this arity");
  524. if (typeArgs.Length == 0)
  525. return typeof (Action);
  526. Type action = null;
  527. switch (typeArgs.Length) {
  528. case 1:
  529. action = typeof (Action<>);
  530. break;
  531. case 2:
  532. action = typeof (Action<,>);
  533. break;
  534. case 3:
  535. action = typeof (Action<,,>);
  536. break;
  537. case 4:
  538. action = typeof (Action<,,,>);
  539. break;
  540. }
  541. return action.MakeGenericType (typeArgs);
  542. }
  543. public static Type GetFuncType (params Type [] typeArgs)
  544. {
  545. if (typeArgs == null)
  546. throw new ArgumentNullException ("typeArgs");
  547. if (typeArgs.Length < 1 || typeArgs.Length > 5)
  548. throw new ArgumentException ("No Func type of this arity");
  549. Type func = null;
  550. switch (typeArgs.Length) {
  551. case 1:
  552. func = typeof (Func<>);
  553. break;
  554. case 2:
  555. func = typeof (Func<,>);
  556. break;
  557. case 3:
  558. func = typeof (Func<,,>);
  559. break;
  560. case 4:
  561. func = typeof (Func<,,,>);
  562. break;
  563. case 5:
  564. func = typeof (Func<,,,,>);
  565. break;
  566. }
  567. return func.MakeGenericType (typeArgs);
  568. }
  569. [MonoTODO]
  570. public static InvocationExpression Invoke (Expression expression, params Expression [] arguments)
  571. {
  572. throw new NotImplementedException ();
  573. }
  574. [MonoTODO]
  575. public static InvocationExpression Invoke (Expression expression, IEnumerable<Expression> arguments)
  576. {
  577. throw new NotImplementedException ();
  578. }
  579. [MonoTODO]
  580. public static Expression<TDelegate> Lambda<TDelegate> (Expression body, params ParameterExpression [] parameters)
  581. {
  582. throw new NotImplementedException ();
  583. }
  584. [MonoTODO]
  585. public static Expression<TDelegate> Lambda<TDelegate> (Expression body, IEnumerable<ParameterExpression> parameters)
  586. {
  587. throw new NotImplementedException ();
  588. }
  589. [MonoTODO]
  590. public static LambdaExpression Lambda (Expression body, params ParameterExpression [] parameters)
  591. {
  592. throw new NotImplementedException ();
  593. }
  594. [MonoTODO]
  595. public static LambdaExpression Lambda (Type delegateType, Expression body, params ParameterExpression [] parameters)
  596. {
  597. throw new NotImplementedException ();
  598. }
  599. [MonoTODO]
  600. public static LambdaExpression Lambda (Type delegateType, Expression body, IEnumerable<ParameterExpression> parameters)
  601. {
  602. throw new NotImplementedException ();
  603. }
  604. public static MemberListBinding ListBind (MemberInfo member, params ElementInit [] initializers)
  605. {
  606. throw new NotImplementedException ();
  607. }
  608. [MonoTODO]
  609. public static MemberListBinding ListBind (MemberInfo member, IEnumerable<ElementInit> initializers)
  610. {
  611. throw new NotImplementedException ();
  612. }
  613. [MonoTODO]
  614. public static MemberListBinding ListBind (MethodInfo propertyAccessor, params ElementInit [] initializers)
  615. {
  616. throw new NotImplementedException ();
  617. }
  618. [MonoTODO]
  619. public static MemberListBinding ListBind (MethodInfo propertyAccessor, IEnumerable<ElementInit> initializers)
  620. {
  621. throw new NotImplementedException ();
  622. }
  623. [MonoTODO]
  624. public static ListInitExpression ListInit (NewExpression newExpression, params ElementInit [] initializers)
  625. {
  626. throw new NotImplementedException ();
  627. }
  628. [MonoTODO]
  629. public static ListInitExpression ListInit (NewExpression newExpression, IEnumerable<ElementInit> initializers)
  630. {
  631. throw new NotImplementedException ();
  632. }
  633. [MonoTODO]
  634. public static ListInitExpression ListInit (NewExpression newExpression, params Expression [] initializers)
  635. {
  636. throw new NotImplementedException ();
  637. }
  638. [MonoTODO]
  639. public static ListInitExpression ListInit (NewExpression newExpression, IEnumerable<Expression> initializers)
  640. {
  641. throw new NotImplementedException ();
  642. }
  643. [MonoTODO]
  644. public static ListInitExpression ListInit (NewExpression newExpression, MethodInfo addMethod, params Expression [] initializers)
  645. {
  646. throw new NotImplementedException ();
  647. }
  648. [MonoTODO]
  649. public static ListInitExpression ListInit (NewExpression newExpression, MethodInfo addMethod, IEnumerable<Expression> initializers)
  650. {
  651. throw new NotImplementedException ();
  652. }
  653. [MonoTODO]
  654. public static MemberExpression MakeMemberAccess (Expression expression, MemberInfo member)
  655. {
  656. throw new NotImplementedException ();
  657. }
  658. public static UnaryExpression MakeUnary (ExpressionType unaryType, Expression operand, Type type)
  659. {
  660. return MakeUnary (unaryType, operand, type, null);
  661. }
  662. public static UnaryExpression MakeUnary (ExpressionType unaryType, Expression operand, Type type, MethodInfo method)
  663. {
  664. switch (unaryType) {
  665. case ExpressionType.ArrayLength:
  666. return ArrayLength (operand);
  667. case ExpressionType.Convert:
  668. return Convert (operand, type, method);
  669. case ExpressionType.ConvertChecked:
  670. return ConvertChecked (operand, type, method);
  671. case ExpressionType.Negate:
  672. return Negate (operand, method);
  673. case ExpressionType.NegateChecked:
  674. return NegateChecked (operand, method);
  675. case ExpressionType.Not:
  676. return Not (operand, method);
  677. case ExpressionType.Quote:
  678. return Quote (operand);
  679. case ExpressionType.TypeAs:
  680. return TypeAs (operand, type);
  681. case ExpressionType.UnaryPlus:
  682. return UnaryPlus (operand, method);
  683. }
  684. throw new ArgumentException ("MakeUnary expect an unary operator");
  685. }
  686. [MonoTODO]
  687. public static MemberMemberBinding MemberBind (MemberInfo member, params MemberBinding [] binding)
  688. {
  689. throw new NotImplementedException ();
  690. }
  691. [MonoTODO]
  692. public static MemberMemberBinding MemberBind (MemberInfo member, IEnumerable<MemberBinding> binding)
  693. {
  694. throw new NotImplementedException ();
  695. }
  696. [MonoTODO]
  697. public static MemberMemberBinding MemberBind (MethodInfo propertyAccessor, params MemberBinding [] binding)
  698. {
  699. throw new NotImplementedException ();
  700. }
  701. [MonoTODO]
  702. public static MemberMemberBinding MemberBind (MethodInfo propertyAccessor, IEnumerable<MemberBinding> binding)
  703. {
  704. throw new NotImplementedException ();
  705. }
  706. [MonoTODO]
  707. public static MemberInitExpression MemberInit (NewExpression newExpression, params MemberBinding [] binding)
  708. {
  709. throw new NotImplementedException ();
  710. }
  711. [MonoTODO]
  712. public static MemberInitExpression MemberInit (NewExpression newExpression, IEnumerable<MemberBinding> binding)
  713. {
  714. throw new NotImplementedException ();
  715. }
  716. [MonoTODO]
  717. public static UnaryExpression Negate (Expression expression)
  718. {
  719. throw new NotImplementedException ();
  720. }
  721. [MonoTODO]
  722. public static UnaryExpression Negate (Expression expression, MethodInfo method)
  723. {
  724. throw new NotImplementedException ();
  725. }
  726. [MonoTODO]
  727. public static UnaryExpression NegateChecked (Expression expression)
  728. {
  729. throw new NotImplementedException ();
  730. }
  731. [MonoTODO]
  732. public static UnaryExpression NegateChecked (Expression expression, MethodInfo method)
  733. {
  734. throw new NotImplementedException ();
  735. }
  736. [MonoTODO]
  737. public static NewExpression New (ConstructorInfo constructor)
  738. {
  739. throw new NotImplementedException ();
  740. }
  741. [MonoTODO]
  742. public static NewExpression New (Type type)
  743. {
  744. throw new NotImplementedException ();
  745. }
  746. [MonoTODO]
  747. public static NewExpression New (ConstructorInfo constructor, params Expression [] arguments)
  748. {
  749. throw new NotImplementedException ();
  750. }
  751. [MonoTODO]
  752. public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments)
  753. {
  754. throw new NotImplementedException ();
  755. }
  756. [MonoTODO]
  757. public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments, params MemberInfo [] members)
  758. {
  759. throw new NotImplementedException ();
  760. }
  761. [MonoTODO]
  762. public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments, IEnumerable<MemberInfo> members)
  763. {
  764. throw new NotImplementedException ();
  765. }
  766. [MonoTODO]
  767. public static NewArrayExpression NewArrayBounds (Type type, params Expression [] bounds)
  768. {
  769. throw new NotImplementedException ();
  770. }
  771. [MonoTODO]
  772. public static NewArrayExpression NewArrayBounds (Type type, IEnumerable<Expression> bounds)
  773. {
  774. throw new NotImplementedException ();
  775. }
  776. [MonoTODO]
  777. public static NewArrayExpression NewArrayInit (Type type, params Expression [] bounds)
  778. {
  779. throw new NotImplementedException ();
  780. }
  781. [MonoTODO]
  782. public static NewArrayExpression NewArrayInit (Type type, IEnumerable<Expression> bounds)
  783. {
  784. throw new NotImplementedException ();
  785. }
  786. [MonoTODO]
  787. public static UnaryExpression Not (Expression expression)
  788. {
  789. throw new NotImplementedException ();
  790. }
  791. [MonoTODO]
  792. public static UnaryExpression Not (Expression expression, MethodInfo method)
  793. {
  794. throw new NotImplementedException ();
  795. }
  796. public static ParameterExpression Parameter (Type type, string name)
  797. {
  798. if (type == null)
  799. throw new ArgumentNullException ("type");
  800. return new ParameterExpression (type, name);
  801. }
  802. [MonoTODO]
  803. public static MemberExpression Property (Expression expression, MethodInfo propertyAccessor)
  804. {
  805. throw new NotImplementedException ();
  806. }
  807. [MonoTODO]
  808. public static MemberExpression Property (Expression expression, PropertyInfo property)
  809. {
  810. throw new NotImplementedException ();
  811. }
  812. [MonoTODO]
  813. public static MemberExpression Property (Expression expression, string propertyName)
  814. {
  815. throw new NotImplementedException ();
  816. }
  817. [MonoTODO]
  818. public static MemberExpression PropertyOrField (Expression expression, string propertyOrFieldName)
  819. {
  820. throw new NotImplementedException ();
  821. }
  822. public static UnaryExpression Quote (Expression expression)
  823. {
  824. if (expression == null)
  825. throw new ArgumentNullException ("expression");
  826. return new UnaryExpression (ExpressionType.Quote, expression, expression.GetType ());
  827. }
  828. public static UnaryExpression TypeAs (Expression expression, Type type)
  829. {
  830. if (expression == null)
  831. throw new ArgumentNullException ("expression");
  832. if (type == null)
  833. throw new ArgumentNullException ("type");
  834. if (type.IsValueType && !IsNullable (type))
  835. throw new ArgumentException ("TypeAs expect a reference or a nullable type");
  836. return new UnaryExpression (ExpressionType.TypeAs, expression, type);
  837. }
  838. public static TypeBinaryExpression TypeIs (Expression expression, Type type)
  839. {
  840. if (expression == null)
  841. throw new ArgumentNullException ("expression");
  842. if (type == null)
  843. throw new ArgumentNullException ("type");
  844. return new TypeBinaryExpression (ExpressionType.TypeIs, expression, type, typeof (bool));
  845. }
  846. [MonoTODO]
  847. public static UnaryExpression UnaryPlus (Expression expression)
  848. {
  849. throw new NotImplementedException ();
  850. }
  851. [MonoTODO]
  852. public static UnaryExpression UnaryPlus (Expression expression, MethodInfo method)
  853. {
  854. throw new NotImplementedException ();
  855. }
  856. static bool IsNullable (Type type)
  857. {
  858. return type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>);
  859. }
  860. }
  861. }