PageRenderTime 116ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 3ms

/IronPython_Main/Runtime/Tests/ETScenariosCSLinq/CSLinq/ExpressionTreeNodes/Not.cs

#
C# | 13447 lines | 11483 code | 1922 blank | 42 comment | 4914 complexity | 666008fde201bf2127369f0fca935e49 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. #if !CLR2
  2. using System.Linq.Expressions;
  3. #else
  4. using Microsoft.Scripting.Ast;
  5. using Microsoft.Scripting.Utils;
  6. #endif
  7. using System.Reflection;
  8. using System.Collections;
  9. using System.Text;
  10. using System.Collections.Generic;
  11. using System;
  12. namespace ExpressionTreeNodes
  13. {
  14. //-------- Scenario 782
  15. namespace Scenario782
  16. {
  17. namespace Not
  18. {
  19. public class Test
  20. {
  21. // expression = null
  22. public static int Test1()
  23. {
  24. ConstantExpression ce = Expression.Constant(10);
  25. try
  26. {
  27. ce = null;
  28. UnaryExpression result = Expression.Not(ce);
  29. return 1;
  30. }
  31. catch (ArgumentNullException ane)
  32. {
  33. if (ane.CompareParamName("expression")) return 0;
  34. return 1;
  35. }
  36. }
  37. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not1__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  38. public static Expression Not1__()
  39. {
  40. if (Main() != 0)
  41. {
  42. throw new Exception();
  43. }
  44. else
  45. {
  46. return Expression.Constant(0);
  47. }
  48. }
  49. public static int Main()
  50. {
  51. return Test1();
  52. }
  53. }
  54. }
  55. public static class Extension
  56. {
  57. public static bool CompareParamName(this ArgumentException ex, string expected)
  58. {
  59. #if SILVERLIGHT
  60. #if SLRESOURCES
  61. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  62. #else
  63. return true;
  64. #endif
  65. #else
  66. return ex.ParamName == expected;
  67. #endif
  68. }
  69. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  70. {
  71. #if SILVERLIGHT
  72. #if SLRESOURCES
  73. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  74. #else
  75. return true;
  76. #endif
  77. #else
  78. return ex.ParamName == expected;
  79. #endif
  80. }
  81. }
  82. public static class Verification
  83. {
  84. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  85. {
  86. if (!(result.NodeType == et))
  87. {
  88. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  89. return 1;
  90. }
  91. if (!(result.Type == type))
  92. {
  93. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  94. return 1;
  95. }
  96. if (val == null)
  97. {
  98. if (result.Value != null) return 1;
  99. }
  100. else
  101. {
  102. if (!(result.Value.Equals(val))) return 1;
  103. }
  104. if (!(result.ToString() == str)) return 1;
  105. return 0;
  106. }
  107. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  108. {
  109. if (!(result.NodeType == et))
  110. {
  111. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  112. return 1;
  113. }
  114. if (!(result.Type == type))
  115. {
  116. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  117. return 1;
  118. }
  119. if (operand == null)
  120. {
  121. if (result.Operand != null) return 1;
  122. }
  123. else
  124. {
  125. if (!(result.Operand.Equals(operand))) return 1;
  126. }
  127. if (!(result.ToString() == str))
  128. {
  129. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  130. return 1;
  131. }
  132. if (result.Method != mi) return 1;
  133. if (result.IsLifted != islifted) return 1;
  134. if (result.IsLiftedToNull != isliftedtonull) return 1;
  135. return 0;
  136. }
  137. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  138. {
  139. if (!(result.NodeType == et))
  140. {
  141. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  142. return 1;
  143. }
  144. if (!(result.Type == type))
  145. {
  146. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  147. return 1;
  148. }
  149. if (left == null)
  150. {
  151. if (result.Left != null)
  152. {
  153. Console.WriteLine("left was null");
  154. return 1;
  155. }
  156. }
  157. else
  158. {
  159. if (!(result.Left.Equals(left)))
  160. {
  161. Console.WriteLine("left was different");
  162. return 1;
  163. }
  164. }
  165. if (right == null)
  166. {
  167. if (result.Right != null) return 1;
  168. }
  169. else
  170. {
  171. if (!(result.Right.Equals(right))) return 1;
  172. }
  173. if (!(result.ToString() == str))
  174. {
  175. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  176. return 1;
  177. }
  178. if (result.Method != mi) return 1;
  179. if (result.IsLifted != islifted) return 1;
  180. if (result.IsLiftedToNull != isliftedtonull) return 1;
  181. if (result.Conversion != null) return 1;
  182. return 0;
  183. }
  184. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  185. {
  186. if (!(result.NodeType == et))
  187. {
  188. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  189. return 1;
  190. }
  191. if (!(result.Type == type))
  192. {
  193. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  194. return 1;
  195. }
  196. if (left == null)
  197. {
  198. if (result.Left != null) return 1;
  199. }
  200. else
  201. {
  202. if (!(result.Left.Equals(left))) return 1;
  203. }
  204. if (right == null)
  205. {
  206. if (result.Right != null) return 1;
  207. }
  208. else
  209. {
  210. if (!(result.Right.Equals(right))) return 1;
  211. }
  212. if (!(result.ToString() == str)) return 1;
  213. if (result.Method != mi) return 1;
  214. if (result.IsLifted != islifted) return 1;
  215. if (result.IsLiftedToNull != isliftedtonull) return 1;
  216. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  217. return 0;
  218. }
  219. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  220. {
  221. if (!(result.NodeType == et))
  222. {
  223. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  224. return 1;
  225. }
  226. if (!(result.Type == type))
  227. {
  228. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  229. return 1;
  230. }
  231. if (!(result.Method == method)) return 1;
  232. if (obj == null)
  233. {
  234. if (result.Object != null)
  235. {
  236. Console.WriteLine("Expected object to be null.");
  237. return 1;
  238. }
  239. }
  240. else
  241. {
  242. if (!(result.Object.Equals(obj)))
  243. {
  244. Console.WriteLine("Object on which call is made is different from the result.");
  245. return 1;
  246. }
  247. }
  248. if (!(result.ToString() == str))
  249. {
  250. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  251. return 1;
  252. }
  253. if (result.Arguments.Count != arguments.Length) return 1;
  254. for (int i = 0; i < arguments.Length; i++)
  255. {
  256. if (result.Arguments[i] != arguments[i]) return 1;
  257. }
  258. return 0;
  259. }
  260. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  261. {
  262. if (!(result.NodeType == et))
  263. {
  264. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  265. return 1;
  266. }
  267. if (!(result.Type == type))
  268. {
  269. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  270. return 1;
  271. }
  272. if (expr == null)
  273. {
  274. Console.WriteLine("expr was null.");
  275. if (result.Expression != null) return 1;
  276. }
  277. else
  278. {
  279. if (!(result.Expression.Equals(expr)))
  280. {
  281. return 1;
  282. }
  283. }
  284. if (!(result.TypeOperand == typeop)) return 1;
  285. if (!(result.ToString() == str))
  286. {
  287. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  288. return 1;
  289. }
  290. return 0;
  291. }
  292. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  293. {
  294. if (!(result.NodeType == et))
  295. {
  296. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  297. return 1;
  298. }
  299. if (!(result.Type == type))
  300. {
  301. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  302. return 1;
  303. }
  304. if (test == null)
  305. {
  306. if (result.Test != null) return 1;
  307. }
  308. else
  309. {
  310. if (!(result.Test.Equals(test))) return 1;
  311. }
  312. if (ifTrue == null)
  313. {
  314. if (result.IfTrue != null) return 1;
  315. }
  316. else
  317. {
  318. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  319. }
  320. if (ifFalse == null)
  321. {
  322. if (result.IfFalse != null) return 1;
  323. }
  324. else
  325. {
  326. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  327. }
  328. if (!(result.ToString() == str)) return 1;
  329. return 0;
  330. }
  331. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  332. {
  333. if (!(result.NodeType == et))
  334. {
  335. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  336. return 1;
  337. }
  338. if (!(result.Type == type))
  339. {
  340. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  341. return 1;
  342. }
  343. if (exp_expr == null)
  344. {
  345. if (result.Expression != null)
  346. {
  347. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  348. return 1;
  349. }
  350. }
  351. else
  352. {
  353. if (!(result.Expression.Equals(exp_expr)))
  354. {
  355. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  356. return 1;
  357. }
  358. }
  359. if (!(result.Member == exp_member))
  360. {
  361. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  362. return 1;
  363. }
  364. if (!(result.ToString() == str))
  365. {
  366. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  367. return 1;
  368. }
  369. return 0;
  370. }
  371. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  372. {
  373. if (!(result.NodeType == et))
  374. {
  375. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  376. return 1;
  377. }
  378. if (!(result.Type == type))
  379. {
  380. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  381. return 1;
  382. }
  383. if (!(result.Constructor == constructor))
  384. {
  385. Console.WriteLine("Unexpected constructor");
  386. return 1;
  387. }
  388. if (!(result.ToString() == str))
  389. {
  390. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  391. return 1;
  392. }
  393. if (arguments == null)
  394. {
  395. if (result.Arguments.Count != 0)
  396. {
  397. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  398. return 1;
  399. }
  400. }
  401. else
  402. {
  403. if (result.Arguments.Count != arguments.Length)
  404. {
  405. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  406. return 1;
  407. }
  408. for (int i = 0; i < arguments.Length; i++)
  409. {
  410. if (result.Arguments[i] != arguments[i])
  411. {
  412. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  413. return 1;
  414. }
  415. }
  416. }
  417. if (result.Members == null)
  418. {
  419. Console.WriteLine("result.Members was null");
  420. return 1;
  421. }
  422. if (members == null)
  423. {
  424. if (result.Members.Count != 0)
  425. {
  426. Console.WriteLine("Got more than zero members");
  427. return 1;
  428. }
  429. }
  430. else
  431. {
  432. if (result.Members.Count != members.Length)
  433. {
  434. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  435. return 1;
  436. }
  437. for (int i = 0; i < members.Length; i++)
  438. {
  439. if (result.Members[i] != members[i])
  440. {
  441. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  442. return 1;
  443. }
  444. }
  445. }
  446. return 0;
  447. }
  448. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  449. {
  450. if (!(result.NodeType == et))
  451. {
  452. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  453. return 1;
  454. }
  455. if (!(result.Type == type))
  456. {
  457. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  458. return 1;
  459. }
  460. if (!(result.Constructor == constructor))
  461. {
  462. Console.WriteLine("Constructor is different from expected.");
  463. return 1;
  464. }
  465. if (!(result.ToString() == str))
  466. {
  467. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  468. return 1;
  469. }
  470. if (result.Arguments.Count != arguments.Length)
  471. {
  472. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  473. return 1;
  474. }
  475. for (int i = 0; i < arguments.Length; i++)
  476. {
  477. if (result.Arguments[i] != arguments[i])
  478. {
  479. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  480. return 1;
  481. }
  482. }
  483. if (result.Members != null)
  484. {
  485. Console.WriteLine("result.Members isn't null");
  486. return 1;
  487. }
  488. return 0;
  489. }
  490. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  491. {
  492. if (!(result.NodeType == et))
  493. {
  494. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  495. return 1;
  496. }
  497. if (!(result.Type == type))
  498. {
  499. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  500. return 1;
  501. }
  502. if (!(result.NewExpression == newExpression)) return 1;
  503. if (!(result.ToString() == str))
  504. {
  505. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  506. return 1;
  507. }
  508. if (result.Initializers.Count != initializers.Length) return 1;
  509. for (int i = 0; i < initializers.Length; i++)
  510. {
  511. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  512. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  513. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  514. {
  515. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  516. }
  517. }
  518. return 0;
  519. }
  520. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  521. {
  522. if (result.AddMethod != exp_mi) return 1;
  523. if (!(result.ToString() == str))
  524. {
  525. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  526. return 1;
  527. }
  528. if (result.Arguments.Count != args.Length) return 1;
  529. for (int i = 0; i < args.Length; i++)
  530. {
  531. if (result.Arguments[i] != args[i]) return 1;
  532. }
  533. return 0;
  534. }
  535. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  536. {
  537. if (!(result.BindingType == bt)) return 1;
  538. if (!(result.Expression == expr)) return 1;
  539. if (!(result.Member.Equals(member))) return 1;
  540. if (!(result.ToString() == str))
  541. {
  542. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  543. return 1;
  544. }
  545. return 0;
  546. }
  547. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  548. {
  549. if (!(result.BindingType == bt)) return 1;
  550. if (!(result.Member.Equals(member))) return 1;
  551. if (!(result.ToString() == str))
  552. {
  553. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  554. return 1;
  555. }
  556. if (result.Initializers.Count != initializers.Length) return 1;
  557. for (int i = 0; i < initializers.Length; i++)
  558. {
  559. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  560. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  561. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  562. {
  563. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  564. }
  565. }
  566. return 0;
  567. }
  568. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  569. {
  570. if (!(result.BindingType == bt)) return 1;
  571. if (!(result.Member.Equals(member))) return 1;
  572. if (!(result.ToString() == str))
  573. {
  574. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  575. return 1;
  576. }
  577. if (result.Bindings.Count != bindings.Length) return 1;
  578. for (int i = 0; i < bindings.Length; i++)
  579. {
  580. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  581. }
  582. return 0;
  583. }
  584. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  585. {
  586. if (!(result.NodeType == et))
  587. {
  588. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  589. return 1;
  590. }
  591. if (!(result.Type == type))
  592. {
  593. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  594. return 1;
  595. }
  596. if (!(result.NewExpression.Equals(newExpr))) return 1;
  597. if (!(result.ToString() == str)) return 1;
  598. if (result.Bindings.Count != bindings.Length) return 1;
  599. for (int i = 0; i < bindings.Length; i++)
  600. {
  601. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  602. }
  603. return 0;
  604. }
  605. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  606. {
  607. if (!(result.NodeType == et))
  608. {
  609. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  610. return 1;
  611. }
  612. if (!(result.Type == type))
  613. {
  614. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  615. return 1;
  616. }
  617. if (result.Expressions.Count != expr.Length) return 1;
  618. for (int i = 0; i < expr.Length; i++)
  619. {
  620. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  621. }
  622. if (!(result.ToString() == str))
  623. {
  624. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  625. return 1;
  626. }
  627. return 0;
  628. }
  629. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  630. {
  631. if (!(result.NodeType == et))
  632. {
  633. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  634. return 1;
  635. }
  636. if (!(result.Type == type))
  637. {
  638. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  639. return 1;
  640. }
  641. if (!(result.Name == name)) return 1;
  642. if (!(result.ToString() == str))
  643. {
  644. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  645. return 1;
  646. }
  647. return 0;
  648. }
  649. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  650. {
  651. if (!(result.NodeType == et))
  652. {
  653. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  654. return 1;
  655. }
  656. if (!(result.Type == type))
  657. {
  658. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  659. return 1;
  660. }
  661. if (expr == null)
  662. {
  663. if (result.Body != null) return 1;
  664. }
  665. else
  666. {
  667. if (!(result.Body.Equals(expr))) return 1;
  668. }
  669. if (result.Parameters.Count != parms.Length) return 1;
  670. for (int i = 0; i < parms.Length; i++)
  671. {
  672. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  673. }
  674. if (!(result.ToString() == str))
  675. {
  676. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  677. return 1;
  678. }
  679. return 0;
  680. }
  681. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  682. {
  683. if (!(result.NodeType == et))
  684. {
  685. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  686. return 1;
  687. }
  688. if (!(result.Type == type))
  689. {
  690. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  691. return 1;
  692. }
  693. if (expr == null)
  694. {
  695. if (result.Expression != null) return 1;
  696. }
  697. else
  698. {
  699. if (!(result.Expression.Equals(expr))) return 1;
  700. }
  701. if (result.Arguments.Count != args.Length) return 1;
  702. for (int i = 0; i < args.Length; i++)
  703. {
  704. if (!(result.Arguments[i].Equals(args[i])))
  705. {
  706. return 1;
  707. }
  708. }
  709. if (result.ToString() != str)
  710. {
  711. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. }
  717. }
  718. //-------- Scenario 783
  719. namespace Scenario783
  720. {
  721. namespace Not
  722. {
  723. public class Test
  724. {
  725. // Test for functionality: Argument is of type integer
  726. public static int Test2()
  727. {
  728. ConstantExpression ce = Expression.Constant(10);
  729. Type exp_type = ce.Type;
  730. ExpressionType exp_et = ExpressionType.Not;
  731. string exp_str = "Not(" + ce.ToString() + ")";
  732. Expression exp_operand = ce;
  733. UnaryExpression result = Expression.Not(ce);
  734. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, null, false, false);
  735. }
  736. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not2__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  737. public static Expression Not2__()
  738. {
  739. if (Main() != 0)
  740. {
  741. throw new Exception();
  742. }
  743. else
  744. {
  745. return Expression.Constant(0);
  746. }
  747. }
  748. public static int Main()
  749. {
  750. return Test2();
  751. }
  752. }
  753. }
  754. public static class Extension
  755. {
  756. public static bool CompareParamName(this ArgumentException ex, string expected)
  757. {
  758. #if SILVERLIGHT
  759. #if SLRESOURCES
  760. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  761. #else
  762. return true;
  763. #endif
  764. #else
  765. return ex.ParamName == expected;
  766. #endif
  767. }
  768. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  769. {
  770. #if SILVERLIGHT
  771. #if SLRESOURCES
  772. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  773. #else
  774. return true;
  775. #endif
  776. #else
  777. return ex.ParamName == expected;
  778. #endif
  779. }
  780. }
  781. public static class Verification
  782. {
  783. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  784. {
  785. if (!(result.NodeType == et))
  786. {
  787. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  788. return 1;
  789. }
  790. if (!(result.Type == type))
  791. {
  792. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  793. return 1;
  794. }
  795. if (val == null)
  796. {
  797. if (result.Value != null) return 1;
  798. }
  799. else
  800. {
  801. if (!(result.Value.Equals(val))) return 1;
  802. }
  803. if (!(result.ToString() == str)) return 1;
  804. return 0;
  805. }
  806. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  807. {
  808. if (!(result.NodeType == et))
  809. {
  810. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  811. return 1;
  812. }
  813. if (!(result.Type == type))
  814. {
  815. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  816. return 1;
  817. }
  818. if (operand == null)
  819. {
  820. if (result.Operand != null) return 1;
  821. }
  822. else
  823. {
  824. if (!(result.Operand.Equals(operand))) return 1;
  825. }
  826. if (!(result.ToString() == str))
  827. {
  828. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  829. return 1;
  830. }
  831. if (result.Method != mi) return 1;
  832. if (result.IsLifted != islifted) return 1;
  833. if (result.IsLiftedToNull != isliftedtonull) return 1;
  834. return 0;
  835. }
  836. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  837. {
  838. if (!(result.NodeType == et))
  839. {
  840. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  841. return 1;
  842. }
  843. if (!(result.Type == type))
  844. {
  845. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  846. return 1;
  847. }
  848. if (left == null)
  849. {
  850. if (result.Left != null)
  851. {
  852. Console.WriteLine("left was null");
  853. return 1;
  854. }
  855. }
  856. else
  857. {
  858. if (!(result.Left.Equals(left)))
  859. {
  860. Console.WriteLine("left was different");
  861. return 1;
  862. }
  863. }
  864. if (right == null)
  865. {
  866. if (result.Right != null) return 1;
  867. }
  868. else
  869. {
  870. if (!(result.Right.Equals(right))) return 1;
  871. }
  872. if (!(result.ToString() == str))
  873. {
  874. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  875. return 1;
  876. }
  877. if (result.Method != mi) return 1;
  878. if (result.IsLifted != islifted) return 1;
  879. if (result.IsLiftedToNull != isliftedtonull) return 1;
  880. if (result.Conversion != null) return 1;
  881. return 0;
  882. }
  883. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  884. {
  885. if (!(result.NodeType == et))
  886. {
  887. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  888. return 1;
  889. }
  890. if (!(result.Type == type))
  891. {
  892. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  893. return 1;
  894. }
  895. if (left == null)
  896. {
  897. if (result.Left != null) return 1;
  898. }
  899. else
  900. {
  901. if (!(result.Left.Equals(left))) return 1;
  902. }
  903. if (right == null)
  904. {
  905. if (result.Right != null) return 1;
  906. }
  907. else
  908. {
  909. if (!(result.Right.Equals(right))) return 1;
  910. }
  911. if (!(result.ToString() == str)) return 1;
  912. if (result.Method != mi) return 1;
  913. if (result.IsLifted != islifted) return 1;
  914. if (result.IsLiftedToNull != isliftedtonull) return 1;
  915. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  916. return 0;
  917. }
  918. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  919. {
  920. if (!(result.NodeType == et))
  921. {
  922. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  923. return 1;
  924. }
  925. if (!(result.Type == type))
  926. {
  927. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  928. return 1;
  929. }
  930. if (!(result.Method == method)) return 1;
  931. if (obj == null)
  932. {
  933. if (result.Object != null)
  934. {
  935. Console.WriteLine("Expected object to be null.");
  936. return 1;
  937. }
  938. }
  939. else
  940. {
  941. if (!(result.Object.Equals(obj)))
  942. {
  943. Console.WriteLine("Object on which call is made is different from the result.");
  944. return 1;
  945. }
  946. }
  947. if (!(result.ToString() == str))
  948. {
  949. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  950. return 1;
  951. }
  952. if (result.Arguments.Count != arguments.Length) return 1;
  953. for (int i = 0; i < arguments.Length; i++)
  954. {
  955. if (result.Arguments[i] != arguments[i]) return 1;
  956. }
  957. return 0;
  958. }
  959. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  960. {
  961. if (!(result.NodeType == et))
  962. {
  963. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  964. return 1;
  965. }
  966. if (!(result.Type == type))
  967. {
  968. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  969. return 1;
  970. }
  971. if (expr == null)
  972. {
  973. Console.WriteLine("expr was null.");
  974. if (result.Expression != null) return 1;
  975. }
  976. else
  977. {
  978. if (!(result.Expression.Equals(expr)))
  979. {
  980. return 1;
  981. }
  982. }
  983. if (!(result.TypeOperand == typeop)) return 1;
  984. if (!(result.ToString() == str))
  985. {
  986. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  987. return 1;
  988. }
  989. return 0;
  990. }
  991. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  992. {
  993. if (!(result.NodeType == et))
  994. {
  995. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  996. return 1;
  997. }
  998. if (!(result.Type == type))
  999. {
  1000. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1001. return 1;
  1002. }
  1003. if (test == null)
  1004. {
  1005. if (result.Test != null) return 1;
  1006. }
  1007. else
  1008. {
  1009. if (!(result.Test.Equals(test))) return 1;
  1010. }
  1011. if (ifTrue == null)
  1012. {
  1013. if (result.IfTrue != null) return 1;
  1014. }
  1015. else
  1016. {
  1017. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  1018. }
  1019. if (ifFalse == null)
  1020. {
  1021. if (result.IfFalse != null) return 1;
  1022. }
  1023. else
  1024. {
  1025. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  1026. }
  1027. if (!(result.ToString() == str)) return 1;
  1028. return 0;
  1029. }
  1030. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  1031. {
  1032. if (!(result.NodeType == et))
  1033. {
  1034. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1035. return 1;
  1036. }
  1037. if (!(result.Type == type))
  1038. {
  1039. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1040. return 1;
  1041. }
  1042. if (exp_expr == null)
  1043. {
  1044. if (result.Expression != null)
  1045. {
  1046. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  1047. return 1;
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if (!(result.Expression.Equals(exp_expr)))
  1053. {
  1054. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  1055. return 1;
  1056. }
  1057. }
  1058. if (!(result.Member == exp_member))
  1059. {
  1060. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  1061. return 1;
  1062. }
  1063. if (!(result.ToString() == str))
  1064. {
  1065. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1066. return 1;
  1067. }
  1068. return 0;
  1069. }
  1070. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  1071. {
  1072. if (!(result.NodeType == et))
  1073. {
  1074. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1075. return 1;
  1076. }
  1077. if (!(result.Type == type))
  1078. {
  1079. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1080. return 1;
  1081. }
  1082. if (!(result.Constructor == constructor))
  1083. {
  1084. Console.WriteLine("Unexpected constructor");
  1085. return 1;
  1086. }
  1087. if (!(result.ToString() == str))
  1088. {
  1089. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1090. return 1;
  1091. }
  1092. if (arguments == null)
  1093. {
  1094. if (result.Arguments.Count != 0)
  1095. {
  1096. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  1097. return 1;
  1098. }
  1099. }
  1100. else
  1101. {
  1102. if (result.Arguments.Count != arguments.Length)
  1103. {
  1104. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  1105. return 1;
  1106. }
  1107. for (int i = 0; i < arguments.Length; i++)
  1108. {
  1109. if (result.Arguments[i] != arguments[i])
  1110. {
  1111. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  1112. return 1;
  1113. }
  1114. }
  1115. }
  1116. if (result.Members == null)
  1117. {
  1118. Console.WriteLine("result.Members was null");
  1119. return 1;
  1120. }
  1121. if (members == null)
  1122. {
  1123. if (result.Members.Count != 0)
  1124. {
  1125. Console.WriteLine("Got more than zero members");
  1126. return 1;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. if (result.Members.Count != members.Length)
  1132. {
  1133. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  1134. return 1;
  1135. }
  1136. for (int i = 0; i < members.Length; i++)
  1137. {
  1138. if (result.Members[i] != members[i])
  1139. {
  1140. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  1141. return 1;
  1142. }
  1143. }
  1144. }
  1145. return 0;
  1146. }
  1147. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  1148. {
  1149. if (!(result.NodeType == et))
  1150. {
  1151. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1152. return 1;
  1153. }
  1154. if (!(result.Type == type))
  1155. {
  1156. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1157. return 1;
  1158. }
  1159. if (!(result.Constructor == constructor))
  1160. {
  1161. Console.WriteLine("Constructor is different from expected.");
  1162. return 1;
  1163. }
  1164. if (!(result.ToString() == str))
  1165. {
  1166. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1167. return 1;
  1168. }
  1169. if (result.Arguments.Count != arguments.Length)
  1170. {
  1171. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  1172. return 1;
  1173. }
  1174. for (int i = 0; i < arguments.Length; i++)
  1175. {
  1176. if (result.Arguments[i] != arguments[i])
  1177. {
  1178. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  1179. return 1;
  1180. }
  1181. }
  1182. if (result.Members != null)
  1183. {
  1184. Console.WriteLine("result.Members isn't null");
  1185. return 1;
  1186. }
  1187. return 0;
  1188. }
  1189. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  1190. {
  1191. if (!(result.NodeType == et))
  1192. {
  1193. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1194. return 1;
  1195. }
  1196. if (!(result.Type == type))
  1197. {
  1198. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1199. return 1;
  1200. }
  1201. if (!(result.NewExpression == newExpression)) return 1;
  1202. if (!(result.ToString() == str))
  1203. {
  1204. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1205. return 1;
  1206. }
  1207. if (result.Initializers.Count != initializers.Length) return 1;
  1208. for (int i = 0; i < initializers.Length; i++)
  1209. {
  1210. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  1211. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  1212. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  1213. {
  1214. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  1215. }
  1216. }
  1217. return 0;
  1218. }
  1219. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  1220. {
  1221. if (result.AddMethod != exp_mi) return 1;
  1222. if (!(result.ToString() == str))
  1223. {
  1224. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1225. return 1;
  1226. }
  1227. if (result.Arguments.Count != args.Length) return 1;
  1228. for (int i = 0; i < args.Length; i++)
  1229. {
  1230. if (result.Arguments[i] != args[i]) return 1;
  1231. }
  1232. return 0;
  1233. }
  1234. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  1235. {
  1236. if (!(result.BindingType == bt)) return 1;
  1237. if (!(result.Expression == expr)) return 1;
  1238. if (!(result.Member.Equals(member))) return 1;
  1239. if (!(result.ToString() == str))
  1240. {
  1241. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1242. return 1;
  1243. }
  1244. return 0;
  1245. }
  1246. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  1247. {
  1248. if (!(result.BindingType == bt)) return 1;
  1249. if (!(result.Member.Equals(member))) return 1;
  1250. if (!(result.ToString() == str))
  1251. {
  1252. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1253. return 1;
  1254. }
  1255. if (result.Initializers.Count != initializers.Length) return 1;
  1256. for (int i = 0; i < initializers.Length; i++)
  1257. {
  1258. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  1259. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  1260. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  1261. {
  1262. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  1263. }
  1264. }
  1265. return 0;
  1266. }
  1267. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  1268. {
  1269. if (!(result.BindingType == bt)) return 1;
  1270. if (!(result.Member.Equals(member))) return 1;
  1271. if (!(result.ToString() == str))
  1272. {
  1273. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1274. return 1;
  1275. }
  1276. if (result.Bindings.Count != bindings.Length) return 1;
  1277. for (int i = 0; i < bindings.Length; i++)
  1278. {
  1279. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  1280. }
  1281. return 0;
  1282. }
  1283. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  1284. {
  1285. if (!(result.NodeType == et))
  1286. {
  1287. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1288. return 1;
  1289. }
  1290. if (!(result.Type == type))
  1291. {
  1292. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1293. return 1;
  1294. }
  1295. if (!(result.NewExpression.Equals(newExpr))) return 1;
  1296. if (!(result.ToString() == str)) return 1;
  1297. if (result.Bindings.Count != bindings.Length) return 1;
  1298. for (int i = 0; i < bindings.Length; i++)
  1299. {
  1300. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  1301. }
  1302. return 0;
  1303. }
  1304. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  1305. {
  1306. if (!(result.NodeType == et))
  1307. {
  1308. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1309. return 1;
  1310. }
  1311. if (!(result.Type == type))
  1312. {
  1313. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1314. return 1;
  1315. }
  1316. if (result.Expressions.Count != expr.Length) return 1;
  1317. for (int i = 0; i < expr.Length; i++)
  1318. {
  1319. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  1320. }
  1321. if (!(result.ToString() == str))
  1322. {
  1323. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1324. return 1;
  1325. }
  1326. return 0;
  1327. }
  1328. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  1329. {
  1330. if (!(result.NodeType == et))
  1331. {
  1332. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1333. return 1;
  1334. }
  1335. if (!(result.Type == type))
  1336. {
  1337. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1338. return 1;
  1339. }
  1340. if (!(result.Name == name)) return 1;
  1341. if (!(result.ToString() == str))
  1342. {
  1343. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1344. return 1;
  1345. }
  1346. return 0;
  1347. }
  1348. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  1349. {
  1350. if (!(result.NodeType == et))
  1351. {
  1352. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1353. return 1;
  1354. }
  1355. if (!(result.Type == type))
  1356. {
  1357. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1358. return 1;
  1359. }
  1360. if (expr == null)
  1361. {
  1362. if (result.Body != null) return 1;
  1363. }
  1364. else
  1365. {
  1366. if (!(result.Body.Equals(expr))) return 1;
  1367. }
  1368. if (result.Parameters.Count != parms.Length) return 1;
  1369. for (int i = 0; i < parms.Length; i++)
  1370. {
  1371. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  1372. }
  1373. if (!(result.ToString() == str))
  1374. {
  1375. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1376. return 1;
  1377. }
  1378. return 0;
  1379. }
  1380. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  1381. {
  1382. if (!(result.NodeType == et))
  1383. {
  1384. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1385. return 1;
  1386. }
  1387. if (!(result.Type == type))
  1388. {
  1389. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1390. return 1;
  1391. }
  1392. if (expr == null)
  1393. {
  1394. if (result.Expression != null) return 1;
  1395. }
  1396. else
  1397. {
  1398. if (!(result.Expression.Equals(expr))) return 1;
  1399. }
  1400. if (result.Arguments.Count != args.Length) return 1;
  1401. for (int i = 0; i < args.Length; i++)
  1402. {
  1403. if (!(result.Arguments[i].Equals(args[i])))
  1404. {
  1405. return 1;
  1406. }
  1407. }
  1408. if (result.ToString() != str)
  1409. {
  1410. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  1411. return 1;
  1412. }
  1413. return 0;
  1414. }
  1415. }
  1416. }
  1417. //-------- Scenario 784
  1418. namespace Scenario784
  1419. {
  1420. namespace Not
  1421. {
  1422. public class Test
  1423. {
  1424. // Test for functionality: Argument is of type bool
  1425. public static int Test3()
  1426. {
  1427. ConstantExpression ce = Expression.Constant(true);
  1428. Type exp_type = ce.Type;
  1429. ExpressionType exp_et = ExpressionType.Not;
  1430. string exp_str = "Not(" + ce.ToString() + ")";
  1431. Expression exp_operand = ce;
  1432. UnaryExpression result = Expression.Not(ce);
  1433. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, null, false, false);
  1434. }
  1435. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not3__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  1436. public static Expression Not3__()
  1437. {
  1438. if (Main() != 0)
  1439. {
  1440. throw new Exception();
  1441. }
  1442. else
  1443. {
  1444. return Expression.Constant(0);
  1445. }
  1446. }
  1447. public static int Main()
  1448. {
  1449. return Test3();
  1450. }
  1451. }
  1452. }
  1453. public static class Extension
  1454. {
  1455. public static bool CompareParamName(this ArgumentException ex, string expected)
  1456. {
  1457. #if SILVERLIGHT
  1458. #if SLRESOURCES
  1459. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  1460. #else
  1461. return true;
  1462. #endif
  1463. #else
  1464. return ex.ParamName == expected;
  1465. #endif
  1466. }
  1467. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  1468. {
  1469. #if SILVERLIGHT
  1470. #if SLRESOURCES
  1471. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  1472. #else
  1473. return true;
  1474. #endif
  1475. #else
  1476. return ex.ParamName == expected;
  1477. #endif
  1478. }
  1479. }
  1480. public static class Verification
  1481. {
  1482. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  1483. {
  1484. if (!(result.NodeType == et))
  1485. {
  1486. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1487. return 1;
  1488. }
  1489. if (!(result.Type == type))
  1490. {
  1491. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1492. return 1;
  1493. }
  1494. if (val == null)
  1495. {
  1496. if (result.Value != null) return 1;
  1497. }
  1498. else
  1499. {
  1500. if (!(result.Value.Equals(val))) return 1;
  1501. }
  1502. if (!(result.ToString() == str)) return 1;
  1503. return 0;
  1504. }
  1505. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  1506. {
  1507. if (!(result.NodeType == et))
  1508. {
  1509. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1510. return 1;
  1511. }
  1512. if (!(result.Type == type))
  1513. {
  1514. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1515. return 1;
  1516. }
  1517. if (operand == null)
  1518. {
  1519. if (result.Operand != null) return 1;
  1520. }
  1521. else
  1522. {
  1523. if (!(result.Operand.Equals(operand))) return 1;
  1524. }
  1525. if (!(result.ToString() == str))
  1526. {
  1527. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  1528. return 1;
  1529. }
  1530. if (result.Method != mi) return 1;
  1531. if (result.IsLifted != islifted) return 1;
  1532. if (result.IsLiftedToNull != isliftedtonull) return 1;
  1533. return 0;
  1534. }
  1535. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  1536. {
  1537. if (!(result.NodeType == et))
  1538. {
  1539. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1540. return 1;
  1541. }
  1542. if (!(result.Type == type))
  1543. {
  1544. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1545. return 1;
  1546. }
  1547. if (left == null)
  1548. {
  1549. if (result.Left != null)
  1550. {
  1551. Console.WriteLine("left was null");
  1552. return 1;
  1553. }
  1554. }
  1555. else
  1556. {
  1557. if (!(result.Left.Equals(left)))
  1558. {
  1559. Console.WriteLine("left was different");
  1560. return 1;
  1561. }
  1562. }
  1563. if (right == null)
  1564. {
  1565. if (result.Right != null) return 1;
  1566. }
  1567. else
  1568. {
  1569. if (!(result.Right.Equals(right))) return 1;
  1570. }
  1571. if (!(result.ToString() == str))
  1572. {
  1573. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  1574. return 1;
  1575. }
  1576. if (result.Method != mi) return 1;
  1577. if (result.IsLifted != islifted) return 1;
  1578. if (result.IsLiftedToNull != isliftedtonull) return 1;
  1579. if (result.Conversion != null) return 1;
  1580. return 0;
  1581. }
  1582. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  1583. {
  1584. if (!(result.NodeType == et))
  1585. {
  1586. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1587. return 1;
  1588. }
  1589. if (!(result.Type == type))
  1590. {
  1591. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1592. return 1;
  1593. }
  1594. if (left == null)
  1595. {
  1596. if (result.Left != null) return 1;
  1597. }
  1598. else
  1599. {
  1600. if (!(result.Left.Equals(left))) return 1;
  1601. }
  1602. if (right == null)
  1603. {
  1604. if (result.Right != null) return 1;
  1605. }
  1606. else
  1607. {
  1608. if (!(result.Right.Equals(right))) return 1;
  1609. }
  1610. if (!(result.ToString() == str)) return 1;
  1611. if (result.Method != mi) return 1;
  1612. if (result.IsLifted != islifted) return 1;
  1613. if (result.IsLiftedToNull != isliftedtonull) return 1;
  1614. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  1615. return 0;
  1616. }
  1617. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  1618. {
  1619. if (!(result.NodeType == et))
  1620. {
  1621. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1622. return 1;
  1623. }
  1624. if (!(result.Type == type))
  1625. {
  1626. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1627. return 1;
  1628. }
  1629. if (!(result.Method == method)) return 1;
  1630. if (obj == null)
  1631. {
  1632. if (result.Object != null)
  1633. {
  1634. Console.WriteLine("Expected object to be null.");
  1635. return 1;
  1636. }
  1637. }
  1638. else
  1639. {
  1640. if (!(result.Object.Equals(obj)))
  1641. {
  1642. Console.WriteLine("Object on which call is made is different from the result.");
  1643. return 1;
  1644. }
  1645. }
  1646. if (!(result.ToString() == str))
  1647. {
  1648. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  1649. return 1;
  1650. }
  1651. if (result.Arguments.Count != arguments.Length) return 1;
  1652. for (int i = 0; i < arguments.Length; i++)
  1653. {
  1654. if (result.Arguments[i] != arguments[i]) return 1;
  1655. }
  1656. return 0;
  1657. }
  1658. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  1659. {
  1660. if (!(result.NodeType == et))
  1661. {
  1662. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1663. return 1;
  1664. }
  1665. if (!(result.Type == type))
  1666. {
  1667. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1668. return 1;
  1669. }
  1670. if (expr == null)
  1671. {
  1672. Console.WriteLine("expr was null.");
  1673. if (result.Expression != null) return 1;
  1674. }
  1675. else
  1676. {
  1677. if (!(result.Expression.Equals(expr)))
  1678. {
  1679. return 1;
  1680. }
  1681. }
  1682. if (!(result.TypeOperand == typeop)) return 1;
  1683. if (!(result.ToString() == str))
  1684. {
  1685. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  1686. return 1;
  1687. }
  1688. return 0;
  1689. }
  1690. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  1691. {
  1692. if (!(result.NodeType == et))
  1693. {
  1694. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1695. return 1;
  1696. }
  1697. if (!(result.Type == type))
  1698. {
  1699. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1700. return 1;
  1701. }
  1702. if (test == null)
  1703. {
  1704. if (result.Test != null) return 1;
  1705. }
  1706. else
  1707. {
  1708. if (!(result.Test.Equals(test))) return 1;
  1709. }
  1710. if (ifTrue == null)
  1711. {
  1712. if (result.IfTrue != null) return 1;
  1713. }
  1714. else
  1715. {
  1716. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  1717. }
  1718. if (ifFalse == null)
  1719. {
  1720. if (result.IfFalse != null) return 1;
  1721. }
  1722. else
  1723. {
  1724. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  1725. }
  1726. if (!(result.ToString() == str)) return 1;
  1727. return 0;
  1728. }
  1729. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  1730. {
  1731. if (!(result.NodeType == et))
  1732. {
  1733. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1734. return 1;
  1735. }
  1736. if (!(result.Type == type))
  1737. {
  1738. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1739. return 1;
  1740. }
  1741. if (exp_expr == null)
  1742. {
  1743. if (result.Expression != null)
  1744. {
  1745. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  1746. return 1;
  1747. }
  1748. }
  1749. else
  1750. {
  1751. if (!(result.Expression.Equals(exp_expr)))
  1752. {
  1753. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  1754. return 1;
  1755. }
  1756. }
  1757. if (!(result.Member == exp_member))
  1758. {
  1759. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  1760. return 1;
  1761. }
  1762. if (!(result.ToString() == str))
  1763. {
  1764. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1765. return 1;
  1766. }
  1767. return 0;
  1768. }
  1769. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  1770. {
  1771. if (!(result.NodeType == et))
  1772. {
  1773. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1774. return 1;
  1775. }
  1776. if (!(result.Type == type))
  1777. {
  1778. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1779. return 1;
  1780. }
  1781. if (!(result.Constructor == constructor))
  1782. {
  1783. Console.WriteLine("Unexpected constructor");
  1784. return 1;
  1785. }
  1786. if (!(result.ToString() == str))
  1787. {
  1788. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1789. return 1;
  1790. }
  1791. if (arguments == null)
  1792. {
  1793. if (result.Arguments.Count != 0)
  1794. {
  1795. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  1796. return 1;
  1797. }
  1798. }
  1799. else
  1800. {
  1801. if (result.Arguments.Count != arguments.Length)
  1802. {
  1803. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  1804. return 1;
  1805. }
  1806. for (int i = 0; i < arguments.Length; i++)
  1807. {
  1808. if (result.Arguments[i] != arguments[i])
  1809. {
  1810. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  1811. return 1;
  1812. }
  1813. }
  1814. }
  1815. if (result.Members == null)
  1816. {
  1817. Console.WriteLine("result.Members was null");
  1818. return 1;
  1819. }
  1820. if (members == null)
  1821. {
  1822. if (result.Members.Count != 0)
  1823. {
  1824. Console.WriteLine("Got more than zero members");
  1825. return 1;
  1826. }
  1827. }
  1828. else
  1829. {
  1830. if (result.Members.Count != members.Length)
  1831. {
  1832. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  1833. return 1;
  1834. }
  1835. for (int i = 0; i < members.Length; i++)
  1836. {
  1837. if (result.Members[i] != members[i])
  1838. {
  1839. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  1840. return 1;
  1841. }
  1842. }
  1843. }
  1844. return 0;
  1845. }
  1846. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  1847. {
  1848. if (!(result.NodeType == et))
  1849. {
  1850. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1851. return 1;
  1852. }
  1853. if (!(result.Type == type))
  1854. {
  1855. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1856. return 1;
  1857. }
  1858. if (!(result.Constructor == constructor))
  1859. {
  1860. Console.WriteLine("Constructor is different from expected.");
  1861. return 1;
  1862. }
  1863. if (!(result.ToString() == str))
  1864. {
  1865. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1866. return 1;
  1867. }
  1868. if (result.Arguments.Count != arguments.Length)
  1869. {
  1870. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  1871. return 1;
  1872. }
  1873. for (int i = 0; i < arguments.Length; i++)
  1874. {
  1875. if (result.Arguments[i] != arguments[i])
  1876. {
  1877. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  1878. return 1;
  1879. }
  1880. }
  1881. if (result.Members != null)
  1882. {
  1883. Console.WriteLine("result.Members isn't null");
  1884. return 1;
  1885. }
  1886. return 0;
  1887. }
  1888. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  1889. {
  1890. if (!(result.NodeType == et))
  1891. {
  1892. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1893. return 1;
  1894. }
  1895. if (!(result.Type == type))
  1896. {
  1897. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1898. return 1;
  1899. }
  1900. if (!(result.NewExpression == newExpression)) return 1;
  1901. if (!(result.ToString() == str))
  1902. {
  1903. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1904. return 1;
  1905. }
  1906. if (result.Initializers.Count != initializers.Length) return 1;
  1907. for (int i = 0; i < initializers.Length; i++)
  1908. {
  1909. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  1910. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  1911. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  1912. {
  1913. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  1914. }
  1915. }
  1916. return 0;
  1917. }
  1918. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  1919. {
  1920. if (result.AddMethod != exp_mi) return 1;
  1921. if (!(result.ToString() == str))
  1922. {
  1923. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1924. return 1;
  1925. }
  1926. if (result.Arguments.Count != args.Length) return 1;
  1927. for (int i = 0; i < args.Length; i++)
  1928. {
  1929. if (result.Arguments[i] != args[i]) return 1;
  1930. }
  1931. return 0;
  1932. }
  1933. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  1934. {
  1935. if (!(result.BindingType == bt)) return 1;
  1936. if (!(result.Expression == expr)) return 1;
  1937. if (!(result.Member.Equals(member))) return 1;
  1938. if (!(result.ToString() == str))
  1939. {
  1940. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1941. return 1;
  1942. }
  1943. return 0;
  1944. }
  1945. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  1946. {
  1947. if (!(result.BindingType == bt)) return 1;
  1948. if (!(result.Member.Equals(member))) return 1;
  1949. if (!(result.ToString() == str))
  1950. {
  1951. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1952. return 1;
  1953. }
  1954. if (result.Initializers.Count != initializers.Length) return 1;
  1955. for (int i = 0; i < initializers.Length; i++)
  1956. {
  1957. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  1958. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  1959. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  1960. {
  1961. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  1962. }
  1963. }
  1964. return 0;
  1965. }
  1966. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  1967. {
  1968. if (!(result.BindingType == bt)) return 1;
  1969. if (!(result.Member.Equals(member))) return 1;
  1970. if (!(result.ToString() == str))
  1971. {
  1972. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1973. return 1;
  1974. }
  1975. if (result.Bindings.Count != bindings.Length) return 1;
  1976. for (int i = 0; i < bindings.Length; i++)
  1977. {
  1978. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  1979. }
  1980. return 0;
  1981. }
  1982. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  1983. {
  1984. if (!(result.NodeType == et))
  1985. {
  1986. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1987. return 1;
  1988. }
  1989. if (!(result.Type == type))
  1990. {
  1991. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1992. return 1;
  1993. }
  1994. if (!(result.NewExpression.Equals(newExpr))) return 1;
  1995. if (!(result.ToString() == str)) return 1;
  1996. if (result.Bindings.Count != bindings.Length) return 1;
  1997. for (int i = 0; i < bindings.Length; i++)
  1998. {
  1999. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  2000. }
  2001. return 0;
  2002. }
  2003. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  2004. {
  2005. if (!(result.NodeType == et))
  2006. {
  2007. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2008. return 1;
  2009. }
  2010. if (!(result.Type == type))
  2011. {
  2012. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2013. return 1;
  2014. }
  2015. if (result.Expressions.Count != expr.Length) return 1;
  2016. for (int i = 0; i < expr.Length; i++)
  2017. {
  2018. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  2019. }
  2020. if (!(result.ToString() == str))
  2021. {
  2022. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2023. return 1;
  2024. }
  2025. return 0;
  2026. }
  2027. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  2028. {
  2029. if (!(result.NodeType == et))
  2030. {
  2031. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2032. return 1;
  2033. }
  2034. if (!(result.Type == type))
  2035. {
  2036. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2037. return 1;
  2038. }
  2039. if (!(result.Name == name)) return 1;
  2040. if (!(result.ToString() == str))
  2041. {
  2042. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2043. return 1;
  2044. }
  2045. return 0;
  2046. }
  2047. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  2048. {
  2049. if (!(result.NodeType == et))
  2050. {
  2051. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2052. return 1;
  2053. }
  2054. if (!(result.Type == type))
  2055. {
  2056. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2057. return 1;
  2058. }
  2059. if (expr == null)
  2060. {
  2061. if (result.Body != null) return 1;
  2062. }
  2063. else
  2064. {
  2065. if (!(result.Body.Equals(expr))) return 1;
  2066. }
  2067. if (result.Parameters.Count != parms.Length) return 1;
  2068. for (int i = 0; i < parms.Length; i++)
  2069. {
  2070. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  2071. }
  2072. if (!(result.ToString() == str))
  2073. {
  2074. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2075. return 1;
  2076. }
  2077. return 0;
  2078. }
  2079. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  2080. {
  2081. if (!(result.NodeType == et))
  2082. {
  2083. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2084. return 1;
  2085. }
  2086. if (!(result.Type == type))
  2087. {
  2088. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2089. return 1;
  2090. }
  2091. if (expr == null)
  2092. {
  2093. if (result.Expression != null) return 1;
  2094. }
  2095. else
  2096. {
  2097. if (!(result.Expression.Equals(expr))) return 1;
  2098. }
  2099. if (result.Arguments.Count != args.Length) return 1;
  2100. for (int i = 0; i < args.Length; i++)
  2101. {
  2102. if (!(result.Arguments[i].Equals(args[i])))
  2103. {
  2104. return 1;
  2105. }
  2106. }
  2107. if (result.ToString() != str)
  2108. {
  2109. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2110. return 1;
  2111. }
  2112. return 0;
  2113. }
  2114. }
  2115. }
  2116. //-------- Scenario 785
  2117. namespace Scenario785
  2118. {
  2119. namespace Not
  2120. {
  2121. public class Test
  2122. {
  2123. // Test for functionality: Argument is of type bool?
  2124. public static int Test4()
  2125. {
  2126. ConstantExpression ce = Expression.Constant(null, typeof(bool?));
  2127. Type exp_type = typeof(bool?);
  2128. ExpressionType exp_et = ExpressionType.Not;
  2129. string exp_str = "Not(" + ce.ToString() + ")";
  2130. Expression exp_operand = ce;
  2131. UnaryExpression result = Expression.Not(ce);
  2132. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, null, true, true);
  2133. }
  2134. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not4__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  2135. public static Expression Not4__()
  2136. {
  2137. if (Main() != 0)
  2138. {
  2139. throw new Exception();
  2140. }
  2141. else
  2142. {
  2143. return Expression.Constant(0);
  2144. }
  2145. }
  2146. public static int Main()
  2147. {
  2148. return Test4();
  2149. }
  2150. }
  2151. }
  2152. public static class Extension
  2153. {
  2154. public static bool CompareParamName(this ArgumentException ex, string expected)
  2155. {
  2156. #if SILVERLIGHT
  2157. #if SLRESOURCES
  2158. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  2159. #else
  2160. return true;
  2161. #endif
  2162. #else
  2163. return ex.ParamName == expected;
  2164. #endif
  2165. }
  2166. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  2167. {
  2168. #if SILVERLIGHT
  2169. #if SLRESOURCES
  2170. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  2171. #else
  2172. return true;
  2173. #endif
  2174. #else
  2175. return ex.ParamName == expected;
  2176. #endif
  2177. }
  2178. }
  2179. public static class Verification
  2180. {
  2181. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  2182. {
  2183. if (!(result.NodeType == et))
  2184. {
  2185. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2186. return 1;
  2187. }
  2188. if (!(result.Type == type))
  2189. {
  2190. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2191. return 1;
  2192. }
  2193. if (val == null)
  2194. {
  2195. if (result.Value != null) return 1;
  2196. }
  2197. else
  2198. {
  2199. if (!(result.Value.Equals(val))) return 1;
  2200. }
  2201. if (!(result.ToString() == str)) return 1;
  2202. return 0;
  2203. }
  2204. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  2205. {
  2206. if (!(result.NodeType == et))
  2207. {
  2208. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2209. return 1;
  2210. }
  2211. if (!(result.Type == type))
  2212. {
  2213. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2214. return 1;
  2215. }
  2216. if (operand == null)
  2217. {
  2218. if (result.Operand != null) return 1;
  2219. }
  2220. else
  2221. {
  2222. if (!(result.Operand.Equals(operand))) return 1;
  2223. }
  2224. if (!(result.ToString() == str))
  2225. {
  2226. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2227. return 1;
  2228. }
  2229. if (result.Method != mi) return 1;
  2230. if (result.IsLifted != islifted) return 1;
  2231. if (result.IsLiftedToNull != isliftedtonull) return 1;
  2232. return 0;
  2233. }
  2234. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  2235. {
  2236. if (!(result.NodeType == et))
  2237. {
  2238. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2239. return 1;
  2240. }
  2241. if (!(result.Type == type))
  2242. {
  2243. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2244. return 1;
  2245. }
  2246. if (left == null)
  2247. {
  2248. if (result.Left != null)
  2249. {
  2250. Console.WriteLine("left was null");
  2251. return 1;
  2252. }
  2253. }
  2254. else
  2255. {
  2256. if (!(result.Left.Equals(left)))
  2257. {
  2258. Console.WriteLine("left was different");
  2259. return 1;
  2260. }
  2261. }
  2262. if (right == null)
  2263. {
  2264. if (result.Right != null) return 1;
  2265. }
  2266. else
  2267. {
  2268. if (!(result.Right.Equals(right))) return 1;
  2269. }
  2270. if (!(result.ToString() == str))
  2271. {
  2272. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2273. return 1;
  2274. }
  2275. if (result.Method != mi) return 1;
  2276. if (result.IsLifted != islifted) return 1;
  2277. if (result.IsLiftedToNull != isliftedtonull) return 1;
  2278. if (result.Conversion != null) return 1;
  2279. return 0;
  2280. }
  2281. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  2282. {
  2283. if (!(result.NodeType == et))
  2284. {
  2285. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2286. return 1;
  2287. }
  2288. if (!(result.Type == type))
  2289. {
  2290. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2291. return 1;
  2292. }
  2293. if (left == null)
  2294. {
  2295. if (result.Left != null) return 1;
  2296. }
  2297. else
  2298. {
  2299. if (!(result.Left.Equals(left))) return 1;
  2300. }
  2301. if (right == null)
  2302. {
  2303. if (result.Right != null) return 1;
  2304. }
  2305. else
  2306. {
  2307. if (!(result.Right.Equals(right))) return 1;
  2308. }
  2309. if (!(result.ToString() == str)) return 1;
  2310. if (result.Method != mi) return 1;
  2311. if (result.IsLifted != islifted) return 1;
  2312. if (result.IsLiftedToNull != isliftedtonull) return 1;
  2313. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  2314. return 0;
  2315. }
  2316. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  2317. {
  2318. if (!(result.NodeType == et))
  2319. {
  2320. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2321. return 1;
  2322. }
  2323. if (!(result.Type == type))
  2324. {
  2325. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2326. return 1;
  2327. }
  2328. if (!(result.Method == method)) return 1;
  2329. if (obj == null)
  2330. {
  2331. if (result.Object != null)
  2332. {
  2333. Console.WriteLine("Expected object to be null.");
  2334. return 1;
  2335. }
  2336. }
  2337. else
  2338. {
  2339. if (!(result.Object.Equals(obj)))
  2340. {
  2341. Console.WriteLine("Object on which call is made is different from the result.");
  2342. return 1;
  2343. }
  2344. }
  2345. if (!(result.ToString() == str))
  2346. {
  2347. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2348. return 1;
  2349. }
  2350. if (result.Arguments.Count != arguments.Length) return 1;
  2351. for (int i = 0; i < arguments.Length; i++)
  2352. {
  2353. if (result.Arguments[i] != arguments[i]) return 1;
  2354. }
  2355. return 0;
  2356. }
  2357. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  2358. {
  2359. if (!(result.NodeType == et))
  2360. {
  2361. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2362. return 1;
  2363. }
  2364. if (!(result.Type == type))
  2365. {
  2366. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2367. return 1;
  2368. }
  2369. if (expr == null)
  2370. {
  2371. Console.WriteLine("expr was null.");
  2372. if (result.Expression != null) return 1;
  2373. }
  2374. else
  2375. {
  2376. if (!(result.Expression.Equals(expr)))
  2377. {
  2378. return 1;
  2379. }
  2380. }
  2381. if (!(result.TypeOperand == typeop)) return 1;
  2382. if (!(result.ToString() == str))
  2383. {
  2384. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2385. return 1;
  2386. }
  2387. return 0;
  2388. }
  2389. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  2390. {
  2391. if (!(result.NodeType == et))
  2392. {
  2393. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2394. return 1;
  2395. }
  2396. if (!(result.Type == type))
  2397. {
  2398. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2399. return 1;
  2400. }
  2401. if (test == null)
  2402. {
  2403. if (result.Test != null) return 1;
  2404. }
  2405. else
  2406. {
  2407. if (!(result.Test.Equals(test))) return 1;
  2408. }
  2409. if (ifTrue == null)
  2410. {
  2411. if (result.IfTrue != null) return 1;
  2412. }
  2413. else
  2414. {
  2415. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  2416. }
  2417. if (ifFalse == null)
  2418. {
  2419. if (result.IfFalse != null) return 1;
  2420. }
  2421. else
  2422. {
  2423. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  2424. }
  2425. if (!(result.ToString() == str)) return 1;
  2426. return 0;
  2427. }
  2428. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  2429. {
  2430. if (!(result.NodeType == et))
  2431. {
  2432. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2433. return 1;
  2434. }
  2435. if (!(result.Type == type))
  2436. {
  2437. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2438. return 1;
  2439. }
  2440. if (exp_expr == null)
  2441. {
  2442. if (result.Expression != null)
  2443. {
  2444. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  2445. return 1;
  2446. }
  2447. }
  2448. else
  2449. {
  2450. if (!(result.Expression.Equals(exp_expr)))
  2451. {
  2452. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  2453. return 1;
  2454. }
  2455. }
  2456. if (!(result.Member == exp_member))
  2457. {
  2458. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  2459. return 1;
  2460. }
  2461. if (!(result.ToString() == str))
  2462. {
  2463. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2464. return 1;
  2465. }
  2466. return 0;
  2467. }
  2468. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  2469. {
  2470. if (!(result.NodeType == et))
  2471. {
  2472. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2473. return 1;
  2474. }
  2475. if (!(result.Type == type))
  2476. {
  2477. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2478. return 1;
  2479. }
  2480. if (!(result.Constructor == constructor))
  2481. {
  2482. Console.WriteLine("Unexpected constructor");
  2483. return 1;
  2484. }
  2485. if (!(result.ToString() == str))
  2486. {
  2487. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2488. return 1;
  2489. }
  2490. if (arguments == null)
  2491. {
  2492. if (result.Arguments.Count != 0)
  2493. {
  2494. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  2495. return 1;
  2496. }
  2497. }
  2498. else
  2499. {
  2500. if (result.Arguments.Count != arguments.Length)
  2501. {
  2502. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  2503. return 1;
  2504. }
  2505. for (int i = 0; i < arguments.Length; i++)
  2506. {
  2507. if (result.Arguments[i] != arguments[i])
  2508. {
  2509. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  2510. return 1;
  2511. }
  2512. }
  2513. }
  2514. if (result.Members == null)
  2515. {
  2516. Console.WriteLine("result.Members was null");
  2517. return 1;
  2518. }
  2519. if (members == null)
  2520. {
  2521. if (result.Members.Count != 0)
  2522. {
  2523. Console.WriteLine("Got more than zero members");
  2524. return 1;
  2525. }
  2526. }
  2527. else
  2528. {
  2529. if (result.Members.Count != members.Length)
  2530. {
  2531. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  2532. return 1;
  2533. }
  2534. for (int i = 0; i < members.Length; i++)
  2535. {
  2536. if (result.Members[i] != members[i])
  2537. {
  2538. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  2539. return 1;
  2540. }
  2541. }
  2542. }
  2543. return 0;
  2544. }
  2545. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  2546. {
  2547. if (!(result.NodeType == et))
  2548. {
  2549. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2550. return 1;
  2551. }
  2552. if (!(result.Type == type))
  2553. {
  2554. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2555. return 1;
  2556. }
  2557. if (!(result.Constructor == constructor))
  2558. {
  2559. Console.WriteLine("Constructor is different from expected.");
  2560. return 1;
  2561. }
  2562. if (!(result.ToString() == str))
  2563. {
  2564. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2565. return 1;
  2566. }
  2567. if (result.Arguments.Count != arguments.Length)
  2568. {
  2569. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  2570. return 1;
  2571. }
  2572. for (int i = 0; i < arguments.Length; i++)
  2573. {
  2574. if (result.Arguments[i] != arguments[i])
  2575. {
  2576. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  2577. return 1;
  2578. }
  2579. }
  2580. if (result.Members != null)
  2581. {
  2582. Console.WriteLine("result.Members isn't null");
  2583. return 1;
  2584. }
  2585. return 0;
  2586. }
  2587. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  2588. {
  2589. if (!(result.NodeType == et))
  2590. {
  2591. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2592. return 1;
  2593. }
  2594. if (!(result.Type == type))
  2595. {
  2596. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2597. return 1;
  2598. }
  2599. if (!(result.NewExpression == newExpression)) return 1;
  2600. if (!(result.ToString() == str))
  2601. {
  2602. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2603. return 1;
  2604. }
  2605. if (result.Initializers.Count != initializers.Length) return 1;
  2606. for (int i = 0; i < initializers.Length; i++)
  2607. {
  2608. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  2609. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  2610. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  2611. {
  2612. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  2613. }
  2614. }
  2615. return 0;
  2616. }
  2617. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  2618. {
  2619. if (result.AddMethod != exp_mi) return 1;
  2620. if (!(result.ToString() == str))
  2621. {
  2622. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2623. return 1;
  2624. }
  2625. if (result.Arguments.Count != args.Length) return 1;
  2626. for (int i = 0; i < args.Length; i++)
  2627. {
  2628. if (result.Arguments[i] != args[i]) return 1;
  2629. }
  2630. return 0;
  2631. }
  2632. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  2633. {
  2634. if (!(result.BindingType == bt)) return 1;
  2635. if (!(result.Expression == expr)) return 1;
  2636. if (!(result.Member.Equals(member))) return 1;
  2637. if (!(result.ToString() == str))
  2638. {
  2639. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2640. return 1;
  2641. }
  2642. return 0;
  2643. }
  2644. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  2645. {
  2646. if (!(result.BindingType == bt)) return 1;
  2647. if (!(result.Member.Equals(member))) return 1;
  2648. if (!(result.ToString() == str))
  2649. {
  2650. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2651. return 1;
  2652. }
  2653. if (result.Initializers.Count != initializers.Length) return 1;
  2654. for (int i = 0; i < initializers.Length; i++)
  2655. {
  2656. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  2657. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  2658. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  2659. {
  2660. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  2661. }
  2662. }
  2663. return 0;
  2664. }
  2665. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  2666. {
  2667. if (!(result.BindingType == bt)) return 1;
  2668. if (!(result.Member.Equals(member))) return 1;
  2669. if (!(result.ToString() == str))
  2670. {
  2671. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2672. return 1;
  2673. }
  2674. if (result.Bindings.Count != bindings.Length) return 1;
  2675. for (int i = 0; i < bindings.Length; i++)
  2676. {
  2677. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  2678. }
  2679. return 0;
  2680. }
  2681. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  2682. {
  2683. if (!(result.NodeType == et))
  2684. {
  2685. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2686. return 1;
  2687. }
  2688. if (!(result.Type == type))
  2689. {
  2690. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2691. return 1;
  2692. }
  2693. if (!(result.NewExpression.Equals(newExpr))) return 1;
  2694. if (!(result.ToString() == str)) return 1;
  2695. if (result.Bindings.Count != bindings.Length) return 1;
  2696. for (int i = 0; i < bindings.Length; i++)
  2697. {
  2698. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  2699. }
  2700. return 0;
  2701. }
  2702. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  2703. {
  2704. if (!(result.NodeType == et))
  2705. {
  2706. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2707. return 1;
  2708. }
  2709. if (!(result.Type == type))
  2710. {
  2711. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2712. return 1;
  2713. }
  2714. if (result.Expressions.Count != expr.Length) return 1;
  2715. for (int i = 0; i < expr.Length; i++)
  2716. {
  2717. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  2718. }
  2719. if (!(result.ToString() == str))
  2720. {
  2721. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2722. return 1;
  2723. }
  2724. return 0;
  2725. }
  2726. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  2727. {
  2728. if (!(result.NodeType == et))
  2729. {
  2730. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2731. return 1;
  2732. }
  2733. if (!(result.Type == type))
  2734. {
  2735. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2736. return 1;
  2737. }
  2738. if (!(result.Name == name)) return 1;
  2739. if (!(result.ToString() == str))
  2740. {
  2741. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2742. return 1;
  2743. }
  2744. return 0;
  2745. }
  2746. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  2747. {
  2748. if (!(result.NodeType == et))
  2749. {
  2750. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2751. return 1;
  2752. }
  2753. if (!(result.Type == type))
  2754. {
  2755. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2756. return 1;
  2757. }
  2758. if (expr == null)
  2759. {
  2760. if (result.Body != null) return 1;
  2761. }
  2762. else
  2763. {
  2764. if (!(result.Body.Equals(expr))) return 1;
  2765. }
  2766. if (result.Parameters.Count != parms.Length) return 1;
  2767. for (int i = 0; i < parms.Length; i++)
  2768. {
  2769. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  2770. }
  2771. if (!(result.ToString() == str))
  2772. {
  2773. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  2774. return 1;
  2775. }
  2776. return 0;
  2777. }
  2778. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  2779. {
  2780. if (!(result.NodeType == et))
  2781. {
  2782. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2783. return 1;
  2784. }
  2785. if (!(result.Type == type))
  2786. {
  2787. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2788. return 1;
  2789. }
  2790. if (expr == null)
  2791. {
  2792. if (result.Expression != null) return 1;
  2793. }
  2794. else
  2795. {
  2796. if (!(result.Expression.Equals(expr))) return 1;
  2797. }
  2798. if (result.Arguments.Count != args.Length) return 1;
  2799. for (int i = 0; i < args.Length; i++)
  2800. {
  2801. if (!(result.Arguments[i].Equals(args[i])))
  2802. {
  2803. return 1;
  2804. }
  2805. }
  2806. if (result.ToString() != str)
  2807. {
  2808. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2809. return 1;
  2810. }
  2811. return 0;
  2812. }
  2813. }
  2814. }
  2815. //-------- Scenario 786
  2816. namespace Scenario786
  2817. {
  2818. namespace Not
  2819. {
  2820. public class Test
  2821. {
  2822. // Test for functionality: Argument is of type long?
  2823. public static int Test5()
  2824. {
  2825. ConstantExpression ce = Expression.Constant(null, typeof(long?));
  2826. Type exp_type = ce.Type;
  2827. ExpressionType exp_et = ExpressionType.Not;
  2828. string exp_str = "Not(" + ce.ToString() + ")";
  2829. Expression exp_operand = ce;
  2830. UnaryExpression result = Expression.Not(ce);
  2831. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, null, true, true);
  2832. }
  2833. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not5__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  2834. public static Expression Not5__()
  2835. {
  2836. if (Main() != 0)
  2837. {
  2838. throw new Exception();
  2839. }
  2840. else
  2841. {
  2842. return Expression.Constant(0);
  2843. }
  2844. }
  2845. public static int Main()
  2846. {
  2847. return Test5();
  2848. }
  2849. }
  2850. }
  2851. public static class Extension
  2852. {
  2853. public static bool CompareParamName(this ArgumentException ex, string expected)
  2854. {
  2855. #if SILVERLIGHT
  2856. #if SLRESOURCES
  2857. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  2858. #else
  2859. return true;
  2860. #endif
  2861. #else
  2862. return ex.ParamName == expected;
  2863. #endif
  2864. }
  2865. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  2866. {
  2867. #if SILVERLIGHT
  2868. #if SLRESOURCES
  2869. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  2870. #else
  2871. return true;
  2872. #endif
  2873. #else
  2874. return ex.ParamName == expected;
  2875. #endif
  2876. }
  2877. }
  2878. public static class Verification
  2879. {
  2880. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  2881. {
  2882. if (!(result.NodeType == et))
  2883. {
  2884. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2885. return 1;
  2886. }
  2887. if (!(result.Type == type))
  2888. {
  2889. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2890. return 1;
  2891. }
  2892. if (val == null)
  2893. {
  2894. if (result.Value != null) return 1;
  2895. }
  2896. else
  2897. {
  2898. if (!(result.Value.Equals(val))) return 1;
  2899. }
  2900. if (!(result.ToString() == str)) return 1;
  2901. return 0;
  2902. }
  2903. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  2904. {
  2905. if (!(result.NodeType == et))
  2906. {
  2907. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2908. return 1;
  2909. }
  2910. if (!(result.Type == type))
  2911. {
  2912. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2913. return 1;
  2914. }
  2915. if (operand == null)
  2916. {
  2917. if (result.Operand != null) return 1;
  2918. }
  2919. else
  2920. {
  2921. if (!(result.Operand.Equals(operand))) return 1;
  2922. }
  2923. if (!(result.ToString() == str))
  2924. {
  2925. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2926. return 1;
  2927. }
  2928. if (result.Method != mi) return 1;
  2929. if (result.IsLifted != islifted) return 1;
  2930. if (result.IsLiftedToNull != isliftedtonull) return 1;
  2931. return 0;
  2932. }
  2933. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  2934. {
  2935. if (!(result.NodeType == et))
  2936. {
  2937. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2938. return 1;
  2939. }
  2940. if (!(result.Type == type))
  2941. {
  2942. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2943. return 1;
  2944. }
  2945. if (left == null)
  2946. {
  2947. if (result.Left != null)
  2948. {
  2949. Console.WriteLine("left was null");
  2950. return 1;
  2951. }
  2952. }
  2953. else
  2954. {
  2955. if (!(result.Left.Equals(left)))
  2956. {
  2957. Console.WriteLine("left was different");
  2958. return 1;
  2959. }
  2960. }
  2961. if (right == null)
  2962. {
  2963. if (result.Right != null) return 1;
  2964. }
  2965. else
  2966. {
  2967. if (!(result.Right.Equals(right))) return 1;
  2968. }
  2969. if (!(result.ToString() == str))
  2970. {
  2971. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  2972. return 1;
  2973. }
  2974. if (result.Method != mi) return 1;
  2975. if (result.IsLifted != islifted) return 1;
  2976. if (result.IsLiftedToNull != isliftedtonull) return 1;
  2977. if (result.Conversion != null) return 1;
  2978. return 0;
  2979. }
  2980. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  2981. {
  2982. if (!(result.NodeType == et))
  2983. {
  2984. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  2985. return 1;
  2986. }
  2987. if (!(result.Type == type))
  2988. {
  2989. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  2990. return 1;
  2991. }
  2992. if (left == null)
  2993. {
  2994. if (result.Left != null) return 1;
  2995. }
  2996. else
  2997. {
  2998. if (!(result.Left.Equals(left))) return 1;
  2999. }
  3000. if (right == null)
  3001. {
  3002. if (result.Right != null) return 1;
  3003. }
  3004. else
  3005. {
  3006. if (!(result.Right.Equals(right))) return 1;
  3007. }
  3008. if (!(result.ToString() == str)) return 1;
  3009. if (result.Method != mi) return 1;
  3010. if (result.IsLifted != islifted) return 1;
  3011. if (result.IsLiftedToNull != isliftedtonull) return 1;
  3012. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  3013. return 0;
  3014. }
  3015. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  3016. {
  3017. if (!(result.NodeType == et))
  3018. {
  3019. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3020. return 1;
  3021. }
  3022. if (!(result.Type == type))
  3023. {
  3024. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3025. return 1;
  3026. }
  3027. if (!(result.Method == method)) return 1;
  3028. if (obj == null)
  3029. {
  3030. if (result.Object != null)
  3031. {
  3032. Console.WriteLine("Expected object to be null.");
  3033. return 1;
  3034. }
  3035. }
  3036. else
  3037. {
  3038. if (!(result.Object.Equals(obj)))
  3039. {
  3040. Console.WriteLine("Object on which call is made is different from the result.");
  3041. return 1;
  3042. }
  3043. }
  3044. if (!(result.ToString() == str))
  3045. {
  3046. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3047. return 1;
  3048. }
  3049. if (result.Arguments.Count != arguments.Length) return 1;
  3050. for (int i = 0; i < arguments.Length; i++)
  3051. {
  3052. if (result.Arguments[i] != arguments[i]) return 1;
  3053. }
  3054. return 0;
  3055. }
  3056. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  3057. {
  3058. if (!(result.NodeType == et))
  3059. {
  3060. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3061. return 1;
  3062. }
  3063. if (!(result.Type == type))
  3064. {
  3065. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3066. return 1;
  3067. }
  3068. if (expr == null)
  3069. {
  3070. Console.WriteLine("expr was null.");
  3071. if (result.Expression != null) return 1;
  3072. }
  3073. else
  3074. {
  3075. if (!(result.Expression.Equals(expr)))
  3076. {
  3077. return 1;
  3078. }
  3079. }
  3080. if (!(result.TypeOperand == typeop)) return 1;
  3081. if (!(result.ToString() == str))
  3082. {
  3083. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3084. return 1;
  3085. }
  3086. return 0;
  3087. }
  3088. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  3089. {
  3090. if (!(result.NodeType == et))
  3091. {
  3092. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3093. return 1;
  3094. }
  3095. if (!(result.Type == type))
  3096. {
  3097. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3098. return 1;
  3099. }
  3100. if (test == null)
  3101. {
  3102. if (result.Test != null) return 1;
  3103. }
  3104. else
  3105. {
  3106. if (!(result.Test.Equals(test))) return 1;
  3107. }
  3108. if (ifTrue == null)
  3109. {
  3110. if (result.IfTrue != null) return 1;
  3111. }
  3112. else
  3113. {
  3114. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  3115. }
  3116. if (ifFalse == null)
  3117. {
  3118. if (result.IfFalse != null) return 1;
  3119. }
  3120. else
  3121. {
  3122. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  3123. }
  3124. if (!(result.ToString() == str)) return 1;
  3125. return 0;
  3126. }
  3127. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  3128. {
  3129. if (!(result.NodeType == et))
  3130. {
  3131. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3132. return 1;
  3133. }
  3134. if (!(result.Type == type))
  3135. {
  3136. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3137. return 1;
  3138. }
  3139. if (exp_expr == null)
  3140. {
  3141. if (result.Expression != null)
  3142. {
  3143. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  3144. return 1;
  3145. }
  3146. }
  3147. else
  3148. {
  3149. if (!(result.Expression.Equals(exp_expr)))
  3150. {
  3151. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  3152. return 1;
  3153. }
  3154. }
  3155. if (!(result.Member == exp_member))
  3156. {
  3157. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  3158. return 1;
  3159. }
  3160. if (!(result.ToString() == str))
  3161. {
  3162. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3163. return 1;
  3164. }
  3165. return 0;
  3166. }
  3167. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  3168. {
  3169. if (!(result.NodeType == et))
  3170. {
  3171. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3172. return 1;
  3173. }
  3174. if (!(result.Type == type))
  3175. {
  3176. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3177. return 1;
  3178. }
  3179. if (!(result.Constructor == constructor))
  3180. {
  3181. Console.WriteLine("Unexpected constructor");
  3182. return 1;
  3183. }
  3184. if (!(result.ToString() == str))
  3185. {
  3186. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3187. return 1;
  3188. }
  3189. if (arguments == null)
  3190. {
  3191. if (result.Arguments.Count != 0)
  3192. {
  3193. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  3194. return 1;
  3195. }
  3196. }
  3197. else
  3198. {
  3199. if (result.Arguments.Count != arguments.Length)
  3200. {
  3201. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  3202. return 1;
  3203. }
  3204. for (int i = 0; i < arguments.Length; i++)
  3205. {
  3206. if (result.Arguments[i] != arguments[i])
  3207. {
  3208. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  3209. return 1;
  3210. }
  3211. }
  3212. }
  3213. if (result.Members == null)
  3214. {
  3215. Console.WriteLine("result.Members was null");
  3216. return 1;
  3217. }
  3218. if (members == null)
  3219. {
  3220. if (result.Members.Count != 0)
  3221. {
  3222. Console.WriteLine("Got more than zero members");
  3223. return 1;
  3224. }
  3225. }
  3226. else
  3227. {
  3228. if (result.Members.Count != members.Length)
  3229. {
  3230. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  3231. return 1;
  3232. }
  3233. for (int i = 0; i < members.Length; i++)
  3234. {
  3235. if (result.Members[i] != members[i])
  3236. {
  3237. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  3238. return 1;
  3239. }
  3240. }
  3241. }
  3242. return 0;
  3243. }
  3244. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  3245. {
  3246. if (!(result.NodeType == et))
  3247. {
  3248. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3249. return 1;
  3250. }
  3251. if (!(result.Type == type))
  3252. {
  3253. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3254. return 1;
  3255. }
  3256. if (!(result.Constructor == constructor))
  3257. {
  3258. Console.WriteLine("Constructor is different from expected.");
  3259. return 1;
  3260. }
  3261. if (!(result.ToString() == str))
  3262. {
  3263. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3264. return 1;
  3265. }
  3266. if (result.Arguments.Count != arguments.Length)
  3267. {
  3268. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  3269. return 1;
  3270. }
  3271. for (int i = 0; i < arguments.Length; i++)
  3272. {
  3273. if (result.Arguments[i] != arguments[i])
  3274. {
  3275. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  3276. return 1;
  3277. }
  3278. }
  3279. if (result.Members != null)
  3280. {
  3281. Console.WriteLine("result.Members isn't null");
  3282. return 1;
  3283. }
  3284. return 0;
  3285. }
  3286. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  3287. {
  3288. if (!(result.NodeType == et))
  3289. {
  3290. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3291. return 1;
  3292. }
  3293. if (!(result.Type == type))
  3294. {
  3295. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3296. return 1;
  3297. }
  3298. if (!(result.NewExpression == newExpression)) return 1;
  3299. if (!(result.ToString() == str))
  3300. {
  3301. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3302. return 1;
  3303. }
  3304. if (result.Initializers.Count != initializers.Length) return 1;
  3305. for (int i = 0; i < initializers.Length; i++)
  3306. {
  3307. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  3308. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  3309. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  3310. {
  3311. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  3312. }
  3313. }
  3314. return 0;
  3315. }
  3316. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  3317. {
  3318. if (result.AddMethod != exp_mi) return 1;
  3319. if (!(result.ToString() == str))
  3320. {
  3321. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3322. return 1;
  3323. }
  3324. if (result.Arguments.Count != args.Length) return 1;
  3325. for (int i = 0; i < args.Length; i++)
  3326. {
  3327. if (result.Arguments[i] != args[i]) return 1;
  3328. }
  3329. return 0;
  3330. }
  3331. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  3332. {
  3333. if (!(result.BindingType == bt)) return 1;
  3334. if (!(result.Expression == expr)) return 1;
  3335. if (!(result.Member.Equals(member))) return 1;
  3336. if (!(result.ToString() == str))
  3337. {
  3338. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3339. return 1;
  3340. }
  3341. return 0;
  3342. }
  3343. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  3344. {
  3345. if (!(result.BindingType == bt)) return 1;
  3346. if (!(result.Member.Equals(member))) return 1;
  3347. if (!(result.ToString() == str))
  3348. {
  3349. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3350. return 1;
  3351. }
  3352. if (result.Initializers.Count != initializers.Length) return 1;
  3353. for (int i = 0; i < initializers.Length; i++)
  3354. {
  3355. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  3356. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  3357. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  3358. {
  3359. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  3360. }
  3361. }
  3362. return 0;
  3363. }
  3364. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  3365. {
  3366. if (!(result.BindingType == bt)) return 1;
  3367. if (!(result.Member.Equals(member))) return 1;
  3368. if (!(result.ToString() == str))
  3369. {
  3370. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3371. return 1;
  3372. }
  3373. if (result.Bindings.Count != bindings.Length) return 1;
  3374. for (int i = 0; i < bindings.Length; i++)
  3375. {
  3376. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  3377. }
  3378. return 0;
  3379. }
  3380. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  3381. {
  3382. if (!(result.NodeType == et))
  3383. {
  3384. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3385. return 1;
  3386. }
  3387. if (!(result.Type == type))
  3388. {
  3389. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3390. return 1;
  3391. }
  3392. if (!(result.NewExpression.Equals(newExpr))) return 1;
  3393. if (!(result.ToString() == str)) return 1;
  3394. if (result.Bindings.Count != bindings.Length) return 1;
  3395. for (int i = 0; i < bindings.Length; i++)
  3396. {
  3397. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  3398. }
  3399. return 0;
  3400. }
  3401. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  3402. {
  3403. if (!(result.NodeType == et))
  3404. {
  3405. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3406. return 1;
  3407. }
  3408. if (!(result.Type == type))
  3409. {
  3410. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3411. return 1;
  3412. }
  3413. if (result.Expressions.Count != expr.Length) return 1;
  3414. for (int i = 0; i < expr.Length; i++)
  3415. {
  3416. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  3417. }
  3418. if (!(result.ToString() == str))
  3419. {
  3420. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3421. return 1;
  3422. }
  3423. return 0;
  3424. }
  3425. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  3426. {
  3427. if (!(result.NodeType == et))
  3428. {
  3429. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3430. return 1;
  3431. }
  3432. if (!(result.Type == type))
  3433. {
  3434. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3435. return 1;
  3436. }
  3437. if (!(result.Name == name)) return 1;
  3438. if (!(result.ToString() == str))
  3439. {
  3440. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3441. return 1;
  3442. }
  3443. return 0;
  3444. }
  3445. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  3446. {
  3447. if (!(result.NodeType == et))
  3448. {
  3449. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3450. return 1;
  3451. }
  3452. if (!(result.Type == type))
  3453. {
  3454. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3455. return 1;
  3456. }
  3457. if (expr == null)
  3458. {
  3459. if (result.Body != null) return 1;
  3460. }
  3461. else
  3462. {
  3463. if (!(result.Body.Equals(expr))) return 1;
  3464. }
  3465. if (result.Parameters.Count != parms.Length) return 1;
  3466. for (int i = 0; i < parms.Length; i++)
  3467. {
  3468. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  3469. }
  3470. if (!(result.ToString() == str))
  3471. {
  3472. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3473. return 1;
  3474. }
  3475. return 0;
  3476. }
  3477. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  3478. {
  3479. if (!(result.NodeType == et))
  3480. {
  3481. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3482. return 1;
  3483. }
  3484. if (!(result.Type == type))
  3485. {
  3486. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3487. return 1;
  3488. }
  3489. if (expr == null)
  3490. {
  3491. if (result.Expression != null) return 1;
  3492. }
  3493. else
  3494. {
  3495. if (!(result.Expression.Equals(expr))) return 1;
  3496. }
  3497. if (result.Arguments.Count != args.Length) return 1;
  3498. for (int i = 0; i < args.Length; i++)
  3499. {
  3500. if (!(result.Arguments[i].Equals(args[i])))
  3501. {
  3502. return 1;
  3503. }
  3504. }
  3505. if (result.ToString() != str)
  3506. {
  3507. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3508. return 1;
  3509. }
  3510. return 0;
  3511. }
  3512. }
  3513. }
  3514. //-------- Scenario 787
  3515. namespace Scenario787
  3516. {
  3517. namespace Not
  3518. {
  3519. public class Test
  3520. {
  3521. // Test for functionality: Argument is of type string
  3522. public static int Test6()
  3523. {
  3524. ConstantExpression ce = Expression.Constant("Test");
  3525. try
  3526. {
  3527. UnaryExpression result = Expression.Not(ce);
  3528. return 1;
  3529. }
  3530. catch (InvalidOperationException)
  3531. {
  3532. return 0;
  3533. }
  3534. }
  3535. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not6__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  3536. public static Expression Not6__()
  3537. {
  3538. if (Main() != 0)
  3539. {
  3540. throw new Exception();
  3541. }
  3542. else
  3543. {
  3544. return Expression.Constant(0);
  3545. }
  3546. }
  3547. public static int Main()
  3548. {
  3549. return Test6();
  3550. }
  3551. }
  3552. }
  3553. public static class Extension
  3554. {
  3555. public static bool CompareParamName(this ArgumentException ex, string expected)
  3556. {
  3557. #if SILVERLIGHT
  3558. #if SLRESOURCES
  3559. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  3560. #else
  3561. return true;
  3562. #endif
  3563. #else
  3564. return ex.ParamName == expected;
  3565. #endif
  3566. }
  3567. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  3568. {
  3569. #if SILVERLIGHT
  3570. #if SLRESOURCES
  3571. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  3572. #else
  3573. return true;
  3574. #endif
  3575. #else
  3576. return ex.ParamName == expected;
  3577. #endif
  3578. }
  3579. }
  3580. public static class Verification
  3581. {
  3582. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  3583. {
  3584. if (!(result.NodeType == et))
  3585. {
  3586. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3587. return 1;
  3588. }
  3589. if (!(result.Type == type))
  3590. {
  3591. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3592. return 1;
  3593. }
  3594. if (val == null)
  3595. {
  3596. if (result.Value != null) return 1;
  3597. }
  3598. else
  3599. {
  3600. if (!(result.Value.Equals(val))) return 1;
  3601. }
  3602. if (!(result.ToString() == str)) return 1;
  3603. return 0;
  3604. }
  3605. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  3606. {
  3607. if (!(result.NodeType == et))
  3608. {
  3609. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3610. return 1;
  3611. }
  3612. if (!(result.Type == type))
  3613. {
  3614. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3615. return 1;
  3616. }
  3617. if (operand == null)
  3618. {
  3619. if (result.Operand != null) return 1;
  3620. }
  3621. else
  3622. {
  3623. if (!(result.Operand.Equals(operand))) return 1;
  3624. }
  3625. if (!(result.ToString() == str))
  3626. {
  3627. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3628. return 1;
  3629. }
  3630. if (result.Method != mi) return 1;
  3631. if (result.IsLifted != islifted) return 1;
  3632. if (result.IsLiftedToNull != isliftedtonull) return 1;
  3633. return 0;
  3634. }
  3635. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  3636. {
  3637. if (!(result.NodeType == et))
  3638. {
  3639. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3640. return 1;
  3641. }
  3642. if (!(result.Type == type))
  3643. {
  3644. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3645. return 1;
  3646. }
  3647. if (left == null)
  3648. {
  3649. if (result.Left != null)
  3650. {
  3651. Console.WriteLine("left was null");
  3652. return 1;
  3653. }
  3654. }
  3655. else
  3656. {
  3657. if (!(result.Left.Equals(left)))
  3658. {
  3659. Console.WriteLine("left was different");
  3660. return 1;
  3661. }
  3662. }
  3663. if (right == null)
  3664. {
  3665. if (result.Right != null) return 1;
  3666. }
  3667. else
  3668. {
  3669. if (!(result.Right.Equals(right))) return 1;
  3670. }
  3671. if (!(result.ToString() == str))
  3672. {
  3673. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3674. return 1;
  3675. }
  3676. if (result.Method != mi) return 1;
  3677. if (result.IsLifted != islifted) return 1;
  3678. if (result.IsLiftedToNull != isliftedtonull) return 1;
  3679. if (result.Conversion != null) return 1;
  3680. return 0;
  3681. }
  3682. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  3683. {
  3684. if (!(result.NodeType == et))
  3685. {
  3686. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3687. return 1;
  3688. }
  3689. if (!(result.Type == type))
  3690. {
  3691. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3692. return 1;
  3693. }
  3694. if (left == null)
  3695. {
  3696. if (result.Left != null) return 1;
  3697. }
  3698. else
  3699. {
  3700. if (!(result.Left.Equals(left))) return 1;
  3701. }
  3702. if (right == null)
  3703. {
  3704. if (result.Right != null) return 1;
  3705. }
  3706. else
  3707. {
  3708. if (!(result.Right.Equals(right))) return 1;
  3709. }
  3710. if (!(result.ToString() == str)) return 1;
  3711. if (result.Method != mi) return 1;
  3712. if (result.IsLifted != islifted) return 1;
  3713. if (result.IsLiftedToNull != isliftedtonull) return 1;
  3714. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  3715. return 0;
  3716. }
  3717. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  3718. {
  3719. if (!(result.NodeType == et))
  3720. {
  3721. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3722. return 1;
  3723. }
  3724. if (!(result.Type == type))
  3725. {
  3726. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3727. return 1;
  3728. }
  3729. if (!(result.Method == method)) return 1;
  3730. if (obj == null)
  3731. {
  3732. if (result.Object != null)
  3733. {
  3734. Console.WriteLine("Expected object to be null.");
  3735. return 1;
  3736. }
  3737. }
  3738. else
  3739. {
  3740. if (!(result.Object.Equals(obj)))
  3741. {
  3742. Console.WriteLine("Object on which call is made is different from the result.");
  3743. return 1;
  3744. }
  3745. }
  3746. if (!(result.ToString() == str))
  3747. {
  3748. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3749. return 1;
  3750. }
  3751. if (result.Arguments.Count != arguments.Length) return 1;
  3752. for (int i = 0; i < arguments.Length; i++)
  3753. {
  3754. if (result.Arguments[i] != arguments[i]) return 1;
  3755. }
  3756. return 0;
  3757. }
  3758. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  3759. {
  3760. if (!(result.NodeType == et))
  3761. {
  3762. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3763. return 1;
  3764. }
  3765. if (!(result.Type == type))
  3766. {
  3767. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3768. return 1;
  3769. }
  3770. if (expr == null)
  3771. {
  3772. Console.WriteLine("expr was null.");
  3773. if (result.Expression != null) return 1;
  3774. }
  3775. else
  3776. {
  3777. if (!(result.Expression.Equals(expr)))
  3778. {
  3779. return 1;
  3780. }
  3781. }
  3782. if (!(result.TypeOperand == typeop)) return 1;
  3783. if (!(result.ToString() == str))
  3784. {
  3785. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  3786. return 1;
  3787. }
  3788. return 0;
  3789. }
  3790. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  3791. {
  3792. if (!(result.NodeType == et))
  3793. {
  3794. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3795. return 1;
  3796. }
  3797. if (!(result.Type == type))
  3798. {
  3799. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3800. return 1;
  3801. }
  3802. if (test == null)
  3803. {
  3804. if (result.Test != null) return 1;
  3805. }
  3806. else
  3807. {
  3808. if (!(result.Test.Equals(test))) return 1;
  3809. }
  3810. if (ifTrue == null)
  3811. {
  3812. if (result.IfTrue != null) return 1;
  3813. }
  3814. else
  3815. {
  3816. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  3817. }
  3818. if (ifFalse == null)
  3819. {
  3820. if (result.IfFalse != null) return 1;
  3821. }
  3822. else
  3823. {
  3824. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  3825. }
  3826. if (!(result.ToString() == str)) return 1;
  3827. return 0;
  3828. }
  3829. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  3830. {
  3831. if (!(result.NodeType == et))
  3832. {
  3833. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3834. return 1;
  3835. }
  3836. if (!(result.Type == type))
  3837. {
  3838. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3839. return 1;
  3840. }
  3841. if (exp_expr == null)
  3842. {
  3843. if (result.Expression != null)
  3844. {
  3845. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  3846. return 1;
  3847. }
  3848. }
  3849. else
  3850. {
  3851. if (!(result.Expression.Equals(exp_expr)))
  3852. {
  3853. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  3854. return 1;
  3855. }
  3856. }
  3857. if (!(result.Member == exp_member))
  3858. {
  3859. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  3860. return 1;
  3861. }
  3862. if (!(result.ToString() == str))
  3863. {
  3864. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3865. return 1;
  3866. }
  3867. return 0;
  3868. }
  3869. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  3870. {
  3871. if (!(result.NodeType == et))
  3872. {
  3873. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3874. return 1;
  3875. }
  3876. if (!(result.Type == type))
  3877. {
  3878. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3879. return 1;
  3880. }
  3881. if (!(result.Constructor == constructor))
  3882. {
  3883. Console.WriteLine("Unexpected constructor");
  3884. return 1;
  3885. }
  3886. if (!(result.ToString() == str))
  3887. {
  3888. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3889. return 1;
  3890. }
  3891. if (arguments == null)
  3892. {
  3893. if (result.Arguments.Count != 0)
  3894. {
  3895. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  3896. return 1;
  3897. }
  3898. }
  3899. else
  3900. {
  3901. if (result.Arguments.Count != arguments.Length)
  3902. {
  3903. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  3904. return 1;
  3905. }
  3906. for (int i = 0; i < arguments.Length; i++)
  3907. {
  3908. if (result.Arguments[i] != arguments[i])
  3909. {
  3910. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  3911. return 1;
  3912. }
  3913. }
  3914. }
  3915. if (result.Members == null)
  3916. {
  3917. Console.WriteLine("result.Members was null");
  3918. return 1;
  3919. }
  3920. if (members == null)
  3921. {
  3922. if (result.Members.Count != 0)
  3923. {
  3924. Console.WriteLine("Got more than zero members");
  3925. return 1;
  3926. }
  3927. }
  3928. else
  3929. {
  3930. if (result.Members.Count != members.Length)
  3931. {
  3932. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  3933. return 1;
  3934. }
  3935. for (int i = 0; i < members.Length; i++)
  3936. {
  3937. if (result.Members[i] != members[i])
  3938. {
  3939. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  3940. return 1;
  3941. }
  3942. }
  3943. }
  3944. return 0;
  3945. }
  3946. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  3947. {
  3948. if (!(result.NodeType == et))
  3949. {
  3950. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3951. return 1;
  3952. }
  3953. if (!(result.Type == type))
  3954. {
  3955. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3956. return 1;
  3957. }
  3958. if (!(result.Constructor == constructor))
  3959. {
  3960. Console.WriteLine("Constructor is different from expected.");
  3961. return 1;
  3962. }
  3963. if (!(result.ToString() == str))
  3964. {
  3965. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  3966. return 1;
  3967. }
  3968. if (result.Arguments.Count != arguments.Length)
  3969. {
  3970. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  3971. return 1;
  3972. }
  3973. for (int i = 0; i < arguments.Length; i++)
  3974. {
  3975. if (result.Arguments[i] != arguments[i])
  3976. {
  3977. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  3978. return 1;
  3979. }
  3980. }
  3981. if (result.Members != null)
  3982. {
  3983. Console.WriteLine("result.Members isn't null");
  3984. return 1;
  3985. }
  3986. return 0;
  3987. }
  3988. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  3989. {
  3990. if (!(result.NodeType == et))
  3991. {
  3992. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  3993. return 1;
  3994. }
  3995. if (!(result.Type == type))
  3996. {
  3997. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  3998. return 1;
  3999. }
  4000. if (!(result.NewExpression == newExpression)) return 1;
  4001. if (!(result.ToString() == str))
  4002. {
  4003. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4004. return 1;
  4005. }
  4006. if (result.Initializers.Count != initializers.Length) return 1;
  4007. for (int i = 0; i < initializers.Length; i++)
  4008. {
  4009. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  4010. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  4011. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  4012. {
  4013. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  4014. }
  4015. }
  4016. return 0;
  4017. }
  4018. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  4019. {
  4020. if (result.AddMethod != exp_mi) return 1;
  4021. if (!(result.ToString() == str))
  4022. {
  4023. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4024. return 1;
  4025. }
  4026. if (result.Arguments.Count != args.Length) return 1;
  4027. for (int i = 0; i < args.Length; i++)
  4028. {
  4029. if (result.Arguments[i] != args[i]) return 1;
  4030. }
  4031. return 0;
  4032. }
  4033. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  4034. {
  4035. if (!(result.BindingType == bt)) return 1;
  4036. if (!(result.Expression == expr)) return 1;
  4037. if (!(result.Member.Equals(member))) return 1;
  4038. if (!(result.ToString() == str))
  4039. {
  4040. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4041. return 1;
  4042. }
  4043. return 0;
  4044. }
  4045. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  4046. {
  4047. if (!(result.BindingType == bt)) return 1;
  4048. if (!(result.Member.Equals(member))) return 1;
  4049. if (!(result.ToString() == str))
  4050. {
  4051. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4052. return 1;
  4053. }
  4054. if (result.Initializers.Count != initializers.Length) return 1;
  4055. for (int i = 0; i < initializers.Length; i++)
  4056. {
  4057. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  4058. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  4059. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  4060. {
  4061. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  4062. }
  4063. }
  4064. return 0;
  4065. }
  4066. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  4067. {
  4068. if (!(result.BindingType == bt)) return 1;
  4069. if (!(result.Member.Equals(member))) return 1;
  4070. if (!(result.ToString() == str))
  4071. {
  4072. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4073. return 1;
  4074. }
  4075. if (result.Bindings.Count != bindings.Length) return 1;
  4076. for (int i = 0; i < bindings.Length; i++)
  4077. {
  4078. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  4079. }
  4080. return 0;
  4081. }
  4082. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  4083. {
  4084. if (!(result.NodeType == et))
  4085. {
  4086. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4087. return 1;
  4088. }
  4089. if (!(result.Type == type))
  4090. {
  4091. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4092. return 1;
  4093. }
  4094. if (!(result.NewExpression.Equals(newExpr))) return 1;
  4095. if (!(result.ToString() == str)) return 1;
  4096. if (result.Bindings.Count != bindings.Length) return 1;
  4097. for (int i = 0; i < bindings.Length; i++)
  4098. {
  4099. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  4100. }
  4101. return 0;
  4102. }
  4103. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  4104. {
  4105. if (!(result.NodeType == et))
  4106. {
  4107. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4108. return 1;
  4109. }
  4110. if (!(result.Type == type))
  4111. {
  4112. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4113. return 1;
  4114. }
  4115. if (result.Expressions.Count != expr.Length) return 1;
  4116. for (int i = 0; i < expr.Length; i++)
  4117. {
  4118. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  4119. }
  4120. if (!(result.ToString() == str))
  4121. {
  4122. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4123. return 1;
  4124. }
  4125. return 0;
  4126. }
  4127. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  4128. {
  4129. if (!(result.NodeType == et))
  4130. {
  4131. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4132. return 1;
  4133. }
  4134. if (!(result.Type == type))
  4135. {
  4136. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4137. return 1;
  4138. }
  4139. if (!(result.Name == name)) return 1;
  4140. if (!(result.ToString() == str))
  4141. {
  4142. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4143. return 1;
  4144. }
  4145. return 0;
  4146. }
  4147. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  4148. {
  4149. if (!(result.NodeType == et))
  4150. {
  4151. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4152. return 1;
  4153. }
  4154. if (!(result.Type == type))
  4155. {
  4156. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4157. return 1;
  4158. }
  4159. if (expr == null)
  4160. {
  4161. if (result.Body != null) return 1;
  4162. }
  4163. else
  4164. {
  4165. if (!(result.Body.Equals(expr))) return 1;
  4166. }
  4167. if (result.Parameters.Count != parms.Length) return 1;
  4168. for (int i = 0; i < parms.Length; i++)
  4169. {
  4170. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  4171. }
  4172. if (!(result.ToString() == str))
  4173. {
  4174. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4175. return 1;
  4176. }
  4177. return 0;
  4178. }
  4179. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  4180. {
  4181. if (!(result.NodeType == et))
  4182. {
  4183. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4184. return 1;
  4185. }
  4186. if (!(result.Type == type))
  4187. {
  4188. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4189. return 1;
  4190. }
  4191. if (expr == null)
  4192. {
  4193. if (result.Expression != null) return 1;
  4194. }
  4195. else
  4196. {
  4197. if (!(result.Expression.Equals(expr))) return 1;
  4198. }
  4199. if (result.Arguments.Count != args.Length) return 1;
  4200. for (int i = 0; i < args.Length; i++)
  4201. {
  4202. if (!(result.Arguments[i].Equals(args[i])))
  4203. {
  4204. return 1;
  4205. }
  4206. }
  4207. if (result.ToString() != str)
  4208. {
  4209. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4210. return 1;
  4211. }
  4212. return 0;
  4213. }
  4214. }
  4215. }
  4216. //-------- Scenario 788
  4217. namespace Scenario788
  4218. {
  4219. namespace Not
  4220. {
  4221. public class Test
  4222. {
  4223. // Overload-1: Test for functionality: Argument is of type user-defined type (Logical Not)
  4224. public static int Test7()
  4225. {
  4226. TC1 ctest = new TC1();
  4227. ConstantExpression ce = Expression.Constant(ctest, typeof(TC1));
  4228. Type exp_type = typeof(TC1);
  4229. ExpressionType exp_et = ExpressionType.Not;
  4230. string exp_str = "Not(" + ce.ToString() + ")";
  4231. Expression exp_operand = ce;
  4232. MethodInfo exp_mi = typeof(TC1).GetMethod("op_LogicalNot");
  4233. UnaryExpression result = Expression.Not(ce);
  4234. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, false, false);
  4235. }
  4236. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not7__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  4237. public static Expression Not7__()
  4238. {
  4239. if (Main() != 0)
  4240. {
  4241. throw new Exception();
  4242. }
  4243. else
  4244. {
  4245. return Expression.Constant(0);
  4246. }
  4247. }
  4248. public static int Main()
  4249. {
  4250. return Test7();
  4251. }
  4252. }
  4253. }
  4254. public static class Extension
  4255. {
  4256. public static bool CompareParamName(this ArgumentException ex, string expected)
  4257. {
  4258. #if SILVERLIGHT
  4259. #if SLRESOURCES
  4260. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  4261. #else
  4262. return true;
  4263. #endif
  4264. #else
  4265. return ex.ParamName == expected;
  4266. #endif
  4267. }
  4268. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  4269. {
  4270. #if SILVERLIGHT
  4271. #if SLRESOURCES
  4272. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  4273. #else
  4274. return true;
  4275. #endif
  4276. #else
  4277. return ex.ParamName == expected;
  4278. #endif
  4279. }
  4280. }
  4281. public static class Verification
  4282. {
  4283. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  4284. {
  4285. if (!(result.NodeType == et))
  4286. {
  4287. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4288. return 1;
  4289. }
  4290. if (!(result.Type == type))
  4291. {
  4292. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4293. return 1;
  4294. }
  4295. if (val == null)
  4296. {
  4297. if (result.Value != null) return 1;
  4298. }
  4299. else
  4300. {
  4301. if (!(result.Value.Equals(val))) return 1;
  4302. }
  4303. if (!(result.ToString() == str)) return 1;
  4304. return 0;
  4305. }
  4306. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  4307. {
  4308. if (!(result.NodeType == et))
  4309. {
  4310. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4311. return 1;
  4312. }
  4313. if (!(result.Type == type))
  4314. {
  4315. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4316. return 1;
  4317. }
  4318. if (operand == null)
  4319. {
  4320. if (result.Operand != null) return 1;
  4321. }
  4322. else
  4323. {
  4324. if (!(result.Operand.Equals(operand))) return 1;
  4325. }
  4326. if (!(result.ToString() == str))
  4327. {
  4328. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4329. return 1;
  4330. }
  4331. if (result.Method != mi) return 1;
  4332. if (result.IsLifted != islifted) return 1;
  4333. if (result.IsLiftedToNull != isliftedtonull) return 1;
  4334. return 0;
  4335. }
  4336. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  4337. {
  4338. if (!(result.NodeType == et))
  4339. {
  4340. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4341. return 1;
  4342. }
  4343. if (!(result.Type == type))
  4344. {
  4345. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4346. return 1;
  4347. }
  4348. if (left == null)
  4349. {
  4350. if (result.Left != null)
  4351. {
  4352. Console.WriteLine("left was null");
  4353. return 1;
  4354. }
  4355. }
  4356. else
  4357. {
  4358. if (!(result.Left.Equals(left)))
  4359. {
  4360. Console.WriteLine("left was different");
  4361. return 1;
  4362. }
  4363. }
  4364. if (right == null)
  4365. {
  4366. if (result.Right != null) return 1;
  4367. }
  4368. else
  4369. {
  4370. if (!(result.Right.Equals(right))) return 1;
  4371. }
  4372. if (!(result.ToString() == str))
  4373. {
  4374. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4375. return 1;
  4376. }
  4377. if (result.Method != mi) return 1;
  4378. if (result.IsLifted != islifted) return 1;
  4379. if (result.IsLiftedToNull != isliftedtonull) return 1;
  4380. if (result.Conversion != null) return 1;
  4381. return 0;
  4382. }
  4383. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  4384. {
  4385. if (!(result.NodeType == et))
  4386. {
  4387. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4388. return 1;
  4389. }
  4390. if (!(result.Type == type))
  4391. {
  4392. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4393. return 1;
  4394. }
  4395. if (left == null)
  4396. {
  4397. if (result.Left != null) return 1;
  4398. }
  4399. else
  4400. {
  4401. if (!(result.Left.Equals(left))) return 1;
  4402. }
  4403. if (right == null)
  4404. {
  4405. if (result.Right != null) return 1;
  4406. }
  4407. else
  4408. {
  4409. if (!(result.Right.Equals(right))) return 1;
  4410. }
  4411. if (!(result.ToString() == str)) return 1;
  4412. if (result.Method != mi) return 1;
  4413. if (result.IsLifted != islifted) return 1;
  4414. if (result.IsLiftedToNull != isliftedtonull) return 1;
  4415. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  4416. return 0;
  4417. }
  4418. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  4419. {
  4420. if (!(result.NodeType == et))
  4421. {
  4422. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4423. return 1;
  4424. }
  4425. if (!(result.Type == type))
  4426. {
  4427. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4428. return 1;
  4429. }
  4430. if (!(result.Method == method)) return 1;
  4431. if (obj == null)
  4432. {
  4433. if (result.Object != null)
  4434. {
  4435. Console.WriteLine("Expected object to be null.");
  4436. return 1;
  4437. }
  4438. }
  4439. else
  4440. {
  4441. if (!(result.Object.Equals(obj)))
  4442. {
  4443. Console.WriteLine("Object on which call is made is different from the result.");
  4444. return 1;
  4445. }
  4446. }
  4447. if (!(result.ToString() == str))
  4448. {
  4449. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4450. return 1;
  4451. }
  4452. if (result.Arguments.Count != arguments.Length) return 1;
  4453. for (int i = 0; i < arguments.Length; i++)
  4454. {
  4455. if (result.Arguments[i] != arguments[i]) return 1;
  4456. }
  4457. return 0;
  4458. }
  4459. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  4460. {
  4461. if (!(result.NodeType == et))
  4462. {
  4463. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4464. return 1;
  4465. }
  4466. if (!(result.Type == type))
  4467. {
  4468. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4469. return 1;
  4470. }
  4471. if (expr == null)
  4472. {
  4473. Console.WriteLine("expr was null.");
  4474. if (result.Expression != null) return 1;
  4475. }
  4476. else
  4477. {
  4478. if (!(result.Expression.Equals(expr)))
  4479. {
  4480. return 1;
  4481. }
  4482. }
  4483. if (!(result.TypeOperand == typeop)) return 1;
  4484. if (!(result.ToString() == str))
  4485. {
  4486. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4487. return 1;
  4488. }
  4489. return 0;
  4490. }
  4491. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  4492. {
  4493. if (!(result.NodeType == et))
  4494. {
  4495. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4496. return 1;
  4497. }
  4498. if (!(result.Type == type))
  4499. {
  4500. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4501. return 1;
  4502. }
  4503. if (test == null)
  4504. {
  4505. if (result.Test != null) return 1;
  4506. }
  4507. else
  4508. {
  4509. if (!(result.Test.Equals(test))) return 1;
  4510. }
  4511. if (ifTrue == null)
  4512. {
  4513. if (result.IfTrue != null) return 1;
  4514. }
  4515. else
  4516. {
  4517. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  4518. }
  4519. if (ifFalse == null)
  4520. {
  4521. if (result.IfFalse != null) return 1;
  4522. }
  4523. else
  4524. {
  4525. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  4526. }
  4527. if (!(result.ToString() == str)) return 1;
  4528. return 0;
  4529. }
  4530. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  4531. {
  4532. if (!(result.NodeType == et))
  4533. {
  4534. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4535. return 1;
  4536. }
  4537. if (!(result.Type == type))
  4538. {
  4539. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4540. return 1;
  4541. }
  4542. if (exp_expr == null)
  4543. {
  4544. if (result.Expression != null)
  4545. {
  4546. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  4547. return 1;
  4548. }
  4549. }
  4550. else
  4551. {
  4552. if (!(result.Expression.Equals(exp_expr)))
  4553. {
  4554. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  4555. return 1;
  4556. }
  4557. }
  4558. if (!(result.Member == exp_member))
  4559. {
  4560. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  4561. return 1;
  4562. }
  4563. if (!(result.ToString() == str))
  4564. {
  4565. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4566. return 1;
  4567. }
  4568. return 0;
  4569. }
  4570. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  4571. {
  4572. if (!(result.NodeType == et))
  4573. {
  4574. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4575. return 1;
  4576. }
  4577. if (!(result.Type == type))
  4578. {
  4579. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4580. return 1;
  4581. }
  4582. if (!(result.Constructor == constructor))
  4583. {
  4584. Console.WriteLine("Unexpected constructor");
  4585. return 1;
  4586. }
  4587. if (!(result.ToString() == str))
  4588. {
  4589. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4590. return 1;
  4591. }
  4592. if (arguments == null)
  4593. {
  4594. if (result.Arguments.Count != 0)
  4595. {
  4596. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  4597. return 1;
  4598. }
  4599. }
  4600. else
  4601. {
  4602. if (result.Arguments.Count != arguments.Length)
  4603. {
  4604. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  4605. return 1;
  4606. }
  4607. for (int i = 0; i < arguments.Length; i++)
  4608. {
  4609. if (result.Arguments[i] != arguments[i])
  4610. {
  4611. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  4612. return 1;
  4613. }
  4614. }
  4615. }
  4616. if (result.Members == null)
  4617. {
  4618. Console.WriteLine("result.Members was null");
  4619. return 1;
  4620. }
  4621. if (members == null)
  4622. {
  4623. if (result.Members.Count != 0)
  4624. {
  4625. Console.WriteLine("Got more than zero members");
  4626. return 1;
  4627. }
  4628. }
  4629. else
  4630. {
  4631. if (result.Members.Count != members.Length)
  4632. {
  4633. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  4634. return 1;
  4635. }
  4636. for (int i = 0; i < members.Length; i++)
  4637. {
  4638. if (result.Members[i] != members[i])
  4639. {
  4640. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  4641. return 1;
  4642. }
  4643. }
  4644. }
  4645. return 0;
  4646. }
  4647. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  4648. {
  4649. if (!(result.NodeType == et))
  4650. {
  4651. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4652. return 1;
  4653. }
  4654. if (!(result.Type == type))
  4655. {
  4656. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4657. return 1;
  4658. }
  4659. if (!(result.Constructor == constructor))
  4660. {
  4661. Console.WriteLine("Constructor is different from expected.");
  4662. return 1;
  4663. }
  4664. if (!(result.ToString() == str))
  4665. {
  4666. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4667. return 1;
  4668. }
  4669. if (result.Arguments.Count != arguments.Length)
  4670. {
  4671. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  4672. return 1;
  4673. }
  4674. for (int i = 0; i < arguments.Length; i++)
  4675. {
  4676. if (result.Arguments[i] != arguments[i])
  4677. {
  4678. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  4679. return 1;
  4680. }
  4681. }
  4682. if (result.Members != null)
  4683. {
  4684. Console.WriteLine("result.Members isn't null");
  4685. return 1;
  4686. }
  4687. return 0;
  4688. }
  4689. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  4690. {
  4691. if (!(result.NodeType == et))
  4692. {
  4693. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4694. return 1;
  4695. }
  4696. if (!(result.Type == type))
  4697. {
  4698. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4699. return 1;
  4700. }
  4701. if (!(result.NewExpression == newExpression)) return 1;
  4702. if (!(result.ToString() == str))
  4703. {
  4704. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4705. return 1;
  4706. }
  4707. if (result.Initializers.Count != initializers.Length) return 1;
  4708. for (int i = 0; i < initializers.Length; i++)
  4709. {
  4710. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  4711. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  4712. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  4713. {
  4714. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  4715. }
  4716. }
  4717. return 0;
  4718. }
  4719. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  4720. {
  4721. if (result.AddMethod != exp_mi) return 1;
  4722. if (!(result.ToString() == str))
  4723. {
  4724. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4725. return 1;
  4726. }
  4727. if (result.Arguments.Count != args.Length) return 1;
  4728. for (int i = 0; i < args.Length; i++)
  4729. {
  4730. if (result.Arguments[i] != args[i]) return 1;
  4731. }
  4732. return 0;
  4733. }
  4734. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  4735. {
  4736. if (!(result.BindingType == bt)) return 1;
  4737. if (!(result.Expression == expr)) return 1;
  4738. if (!(result.Member.Equals(member))) return 1;
  4739. if (!(result.ToString() == str))
  4740. {
  4741. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4742. return 1;
  4743. }
  4744. return 0;
  4745. }
  4746. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  4747. {
  4748. if (!(result.BindingType == bt)) return 1;
  4749. if (!(result.Member.Equals(member))) return 1;
  4750. if (!(result.ToString() == str))
  4751. {
  4752. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4753. return 1;
  4754. }
  4755. if (result.Initializers.Count != initializers.Length) return 1;
  4756. for (int i = 0; i < initializers.Length; i++)
  4757. {
  4758. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  4759. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  4760. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  4761. {
  4762. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  4763. }
  4764. }
  4765. return 0;
  4766. }
  4767. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  4768. {
  4769. if (!(result.BindingType == bt)) return 1;
  4770. if (!(result.Member.Equals(member))) return 1;
  4771. if (!(result.ToString() == str))
  4772. {
  4773. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4774. return 1;
  4775. }
  4776. if (result.Bindings.Count != bindings.Length) return 1;
  4777. for (int i = 0; i < bindings.Length; i++)
  4778. {
  4779. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  4780. }
  4781. return 0;
  4782. }
  4783. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  4784. {
  4785. if (!(result.NodeType == et))
  4786. {
  4787. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4788. return 1;
  4789. }
  4790. if (!(result.Type == type))
  4791. {
  4792. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4793. return 1;
  4794. }
  4795. if (!(result.NewExpression.Equals(newExpr))) return 1;
  4796. if (!(result.ToString() == str)) return 1;
  4797. if (result.Bindings.Count != bindings.Length) return 1;
  4798. for (int i = 0; i < bindings.Length; i++)
  4799. {
  4800. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  4801. }
  4802. return 0;
  4803. }
  4804. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  4805. {
  4806. if (!(result.NodeType == et))
  4807. {
  4808. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4809. return 1;
  4810. }
  4811. if (!(result.Type == type))
  4812. {
  4813. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4814. return 1;
  4815. }
  4816. if (result.Expressions.Count != expr.Length) return 1;
  4817. for (int i = 0; i < expr.Length; i++)
  4818. {
  4819. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  4820. }
  4821. if (!(result.ToString() == str))
  4822. {
  4823. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4824. return 1;
  4825. }
  4826. return 0;
  4827. }
  4828. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  4829. {
  4830. if (!(result.NodeType == et))
  4831. {
  4832. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4833. return 1;
  4834. }
  4835. if (!(result.Type == type))
  4836. {
  4837. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4838. return 1;
  4839. }
  4840. if (!(result.Name == name)) return 1;
  4841. if (!(result.ToString() == str))
  4842. {
  4843. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4844. return 1;
  4845. }
  4846. return 0;
  4847. }
  4848. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  4849. {
  4850. if (!(result.NodeType == et))
  4851. {
  4852. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4853. return 1;
  4854. }
  4855. if (!(result.Type == type))
  4856. {
  4857. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4858. return 1;
  4859. }
  4860. if (expr == null)
  4861. {
  4862. if (result.Body != null) return 1;
  4863. }
  4864. else
  4865. {
  4866. if (!(result.Body.Equals(expr))) return 1;
  4867. }
  4868. if (result.Parameters.Count != parms.Length) return 1;
  4869. for (int i = 0; i < parms.Length; i++)
  4870. {
  4871. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  4872. }
  4873. if (!(result.ToString() == str))
  4874. {
  4875. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  4876. return 1;
  4877. }
  4878. return 0;
  4879. }
  4880. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  4881. {
  4882. if (!(result.NodeType == et))
  4883. {
  4884. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  4885. return 1;
  4886. }
  4887. if (!(result.Type == type))
  4888. {
  4889. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  4890. return 1;
  4891. }
  4892. if (expr == null)
  4893. {
  4894. if (result.Expression != null) return 1;
  4895. }
  4896. else
  4897. {
  4898. if (!(result.Expression.Equals(expr))) return 1;
  4899. }
  4900. if (result.Arguments.Count != args.Length) return 1;
  4901. for (int i = 0; i < args.Length; i++)
  4902. {
  4903. if (!(result.Arguments[i].Equals(args[i])))
  4904. {
  4905. return 1;
  4906. }
  4907. }
  4908. if (result.ToString() != str)
  4909. {
  4910. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  4911. return 1;
  4912. }
  4913. return 0;
  4914. }
  4915. }
  4916. namespace Not
  4917. {
  4918. // Declaring user-defined types for testing
  4919. struct TC1
  4920. {
  4921. public static TC1 operator !(TC1 c)
  4922. {
  4923. return new TC1();
  4924. }
  4925. public static TC1 operator ~(TC1 c)
  4926. {
  4927. return new TC1();
  4928. }
  4929. }
  4930. struct TC2
  4931. {
  4932. public static TC2 operator ~(TC2 c)
  4933. {
  4934. return new TC2();
  4935. }
  4936. }
  4937. struct TC3
  4938. {
  4939. public static TC3 Meth1(TC3 c)
  4940. {
  4941. return new TC3();
  4942. }
  4943. }
  4944. }
  4945. }
  4946. //-------- Scenario 789
  4947. namespace Scenario789
  4948. {
  4949. namespace Not
  4950. {
  4951. public class Test
  4952. {
  4953. // Overload-1: Test for functionality: Argument is of type nullable user-defined type (Logical Not)
  4954. public static int Test8()
  4955. {
  4956. TC1? ctest = new TC1?();
  4957. ConstantExpression ce = Expression.Constant(ctest, typeof(TC1?));
  4958. Type exp_type = typeof(TC1?);
  4959. ExpressionType exp_et = ExpressionType.Not;
  4960. string exp_str = "Not(" + ce.ToString() + ")";
  4961. Expression exp_operand = ce;
  4962. MethodInfo exp_mi = typeof(TC1).GetMethod("op_LogicalNot");
  4963. UnaryExpression result = Expression.Not(ce);
  4964. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, true, true);
  4965. }
  4966. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not8__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  4967. public static Expression Not8__()
  4968. {
  4969. if (Main() != 0)
  4970. {
  4971. throw new Exception();
  4972. }
  4973. else
  4974. {
  4975. return Expression.Constant(0);
  4976. }
  4977. }
  4978. public static int Main()
  4979. {
  4980. return Test8();
  4981. }
  4982. }
  4983. }
  4984. public static class Extension
  4985. {
  4986. public static bool CompareParamName(this ArgumentException ex, string expected)
  4987. {
  4988. #if SILVERLIGHT
  4989. #if SLRESOURCES
  4990. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  4991. #else
  4992. return true;
  4993. #endif
  4994. #else
  4995. return ex.ParamName == expected;
  4996. #endif
  4997. }
  4998. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  4999. {
  5000. #if SILVERLIGHT
  5001. #if SLRESOURCES
  5002. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  5003. #else
  5004. return true;
  5005. #endif
  5006. #else
  5007. return ex.ParamName == expected;
  5008. #endif
  5009. }
  5010. }
  5011. public static class Verification
  5012. {
  5013. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  5014. {
  5015. if (!(result.NodeType == et))
  5016. {
  5017. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5018. return 1;
  5019. }
  5020. if (!(result.Type == type))
  5021. {
  5022. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5023. return 1;
  5024. }
  5025. if (val == null)
  5026. {
  5027. if (result.Value != null) return 1;
  5028. }
  5029. else
  5030. {
  5031. if (!(result.Value.Equals(val))) return 1;
  5032. }
  5033. if (!(result.ToString() == str)) return 1;
  5034. return 0;
  5035. }
  5036. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  5037. {
  5038. if (!(result.NodeType == et))
  5039. {
  5040. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5041. return 1;
  5042. }
  5043. if (!(result.Type == type))
  5044. {
  5045. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5046. return 1;
  5047. }
  5048. if (operand == null)
  5049. {
  5050. if (result.Operand != null) return 1;
  5051. }
  5052. else
  5053. {
  5054. if (!(result.Operand.Equals(operand))) return 1;
  5055. }
  5056. if (!(result.ToString() == str))
  5057. {
  5058. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5059. return 1;
  5060. }
  5061. if (result.Method != mi) return 1;
  5062. if (result.IsLifted != islifted) return 1;
  5063. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5064. return 0;
  5065. }
  5066. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  5067. {
  5068. if (!(result.NodeType == et))
  5069. {
  5070. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5071. return 1;
  5072. }
  5073. if (!(result.Type == type))
  5074. {
  5075. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5076. return 1;
  5077. }
  5078. if (left == null)
  5079. {
  5080. if (result.Left != null)
  5081. {
  5082. Console.WriteLine("left was null");
  5083. return 1;
  5084. }
  5085. }
  5086. else
  5087. {
  5088. if (!(result.Left.Equals(left)))
  5089. {
  5090. Console.WriteLine("left was different");
  5091. return 1;
  5092. }
  5093. }
  5094. if (right == null)
  5095. {
  5096. if (result.Right != null) return 1;
  5097. }
  5098. else
  5099. {
  5100. if (!(result.Right.Equals(right))) return 1;
  5101. }
  5102. if (!(result.ToString() == str))
  5103. {
  5104. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5105. return 1;
  5106. }
  5107. if (result.Method != mi) return 1;
  5108. if (result.IsLifted != islifted) return 1;
  5109. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5110. if (result.Conversion != null) return 1;
  5111. return 0;
  5112. }
  5113. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  5114. {
  5115. if (!(result.NodeType == et))
  5116. {
  5117. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5118. return 1;
  5119. }
  5120. if (!(result.Type == type))
  5121. {
  5122. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5123. return 1;
  5124. }
  5125. if (left == null)
  5126. {
  5127. if (result.Left != null) return 1;
  5128. }
  5129. else
  5130. {
  5131. if (!(result.Left.Equals(left))) return 1;
  5132. }
  5133. if (right == null)
  5134. {
  5135. if (result.Right != null) return 1;
  5136. }
  5137. else
  5138. {
  5139. if (!(result.Right.Equals(right))) return 1;
  5140. }
  5141. if (!(result.ToString() == str)) return 1;
  5142. if (result.Method != mi) return 1;
  5143. if (result.IsLifted != islifted) return 1;
  5144. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5145. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  5146. return 0;
  5147. }
  5148. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  5149. {
  5150. if (!(result.NodeType == et))
  5151. {
  5152. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5153. return 1;
  5154. }
  5155. if (!(result.Type == type))
  5156. {
  5157. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5158. return 1;
  5159. }
  5160. if (!(result.Method == method)) return 1;
  5161. if (obj == null)
  5162. {
  5163. if (result.Object != null)
  5164. {
  5165. Console.WriteLine("Expected object to be null.");
  5166. return 1;
  5167. }
  5168. }
  5169. else
  5170. {
  5171. if (!(result.Object.Equals(obj)))
  5172. {
  5173. Console.WriteLine("Object on which call is made is different from the result.");
  5174. return 1;
  5175. }
  5176. }
  5177. if (!(result.ToString() == str))
  5178. {
  5179. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5180. return 1;
  5181. }
  5182. if (result.Arguments.Count != arguments.Length) return 1;
  5183. for (int i = 0; i < arguments.Length; i++)
  5184. {
  5185. if (result.Arguments[i] != arguments[i]) return 1;
  5186. }
  5187. return 0;
  5188. }
  5189. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  5190. {
  5191. if (!(result.NodeType == et))
  5192. {
  5193. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5194. return 1;
  5195. }
  5196. if (!(result.Type == type))
  5197. {
  5198. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5199. return 1;
  5200. }
  5201. if (expr == null)
  5202. {
  5203. Console.WriteLine("expr was null.");
  5204. if (result.Expression != null) return 1;
  5205. }
  5206. else
  5207. {
  5208. if (!(result.Expression.Equals(expr)))
  5209. {
  5210. return 1;
  5211. }
  5212. }
  5213. if (!(result.TypeOperand == typeop)) return 1;
  5214. if (!(result.ToString() == str))
  5215. {
  5216. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5217. return 1;
  5218. }
  5219. return 0;
  5220. }
  5221. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  5222. {
  5223. if (!(result.NodeType == et))
  5224. {
  5225. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5226. return 1;
  5227. }
  5228. if (!(result.Type == type))
  5229. {
  5230. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5231. return 1;
  5232. }
  5233. if (test == null)
  5234. {
  5235. if (result.Test != null) return 1;
  5236. }
  5237. else
  5238. {
  5239. if (!(result.Test.Equals(test))) return 1;
  5240. }
  5241. if (ifTrue == null)
  5242. {
  5243. if (result.IfTrue != null) return 1;
  5244. }
  5245. else
  5246. {
  5247. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  5248. }
  5249. if (ifFalse == null)
  5250. {
  5251. if (result.IfFalse != null) return 1;
  5252. }
  5253. else
  5254. {
  5255. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  5256. }
  5257. if (!(result.ToString() == str)) return 1;
  5258. return 0;
  5259. }
  5260. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  5261. {
  5262. if (!(result.NodeType == et))
  5263. {
  5264. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5265. return 1;
  5266. }
  5267. if (!(result.Type == type))
  5268. {
  5269. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5270. return 1;
  5271. }
  5272. if (exp_expr == null)
  5273. {
  5274. if (result.Expression != null)
  5275. {
  5276. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  5277. return 1;
  5278. }
  5279. }
  5280. else
  5281. {
  5282. if (!(result.Expression.Equals(exp_expr)))
  5283. {
  5284. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  5285. return 1;
  5286. }
  5287. }
  5288. if (!(result.Member == exp_member))
  5289. {
  5290. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  5291. return 1;
  5292. }
  5293. if (!(result.ToString() == str))
  5294. {
  5295. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5296. return 1;
  5297. }
  5298. return 0;
  5299. }
  5300. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  5301. {
  5302. if (!(result.NodeType == et))
  5303. {
  5304. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5305. return 1;
  5306. }
  5307. if (!(result.Type == type))
  5308. {
  5309. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5310. return 1;
  5311. }
  5312. if (!(result.Constructor == constructor))
  5313. {
  5314. Console.WriteLine("Unexpected constructor");
  5315. return 1;
  5316. }
  5317. if (!(result.ToString() == str))
  5318. {
  5319. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5320. return 1;
  5321. }
  5322. if (arguments == null)
  5323. {
  5324. if (result.Arguments.Count != 0)
  5325. {
  5326. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  5327. return 1;
  5328. }
  5329. }
  5330. else
  5331. {
  5332. if (result.Arguments.Count != arguments.Length)
  5333. {
  5334. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  5335. return 1;
  5336. }
  5337. for (int i = 0; i < arguments.Length; i++)
  5338. {
  5339. if (result.Arguments[i] != arguments[i])
  5340. {
  5341. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  5342. return 1;
  5343. }
  5344. }
  5345. }
  5346. if (result.Members == null)
  5347. {
  5348. Console.WriteLine("result.Members was null");
  5349. return 1;
  5350. }
  5351. if (members == null)
  5352. {
  5353. if (result.Members.Count != 0)
  5354. {
  5355. Console.WriteLine("Got more than zero members");
  5356. return 1;
  5357. }
  5358. }
  5359. else
  5360. {
  5361. if (result.Members.Count != members.Length)
  5362. {
  5363. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  5364. return 1;
  5365. }
  5366. for (int i = 0; i < members.Length; i++)
  5367. {
  5368. if (result.Members[i] != members[i])
  5369. {
  5370. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  5371. return 1;
  5372. }
  5373. }
  5374. }
  5375. return 0;
  5376. }
  5377. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  5378. {
  5379. if (!(result.NodeType == et))
  5380. {
  5381. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5382. return 1;
  5383. }
  5384. if (!(result.Type == type))
  5385. {
  5386. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5387. return 1;
  5388. }
  5389. if (!(result.Constructor == constructor))
  5390. {
  5391. Console.WriteLine("Constructor is different from expected.");
  5392. return 1;
  5393. }
  5394. if (!(result.ToString() == str))
  5395. {
  5396. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5397. return 1;
  5398. }
  5399. if (result.Arguments.Count != arguments.Length)
  5400. {
  5401. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  5402. return 1;
  5403. }
  5404. for (int i = 0; i < arguments.Length; i++)
  5405. {
  5406. if (result.Arguments[i] != arguments[i])
  5407. {
  5408. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  5409. return 1;
  5410. }
  5411. }
  5412. if (result.Members != null)
  5413. {
  5414. Console.WriteLine("result.Members isn't null");
  5415. return 1;
  5416. }
  5417. return 0;
  5418. }
  5419. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  5420. {
  5421. if (!(result.NodeType == et))
  5422. {
  5423. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5424. return 1;
  5425. }
  5426. if (!(result.Type == type))
  5427. {
  5428. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5429. return 1;
  5430. }
  5431. if (!(result.NewExpression == newExpression)) return 1;
  5432. if (!(result.ToString() == str))
  5433. {
  5434. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5435. return 1;
  5436. }
  5437. if (result.Initializers.Count != initializers.Length) return 1;
  5438. for (int i = 0; i < initializers.Length; i++)
  5439. {
  5440. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  5441. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  5442. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  5443. {
  5444. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  5445. }
  5446. }
  5447. return 0;
  5448. }
  5449. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  5450. {
  5451. if (result.AddMethod != exp_mi) return 1;
  5452. if (!(result.ToString() == str))
  5453. {
  5454. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5455. return 1;
  5456. }
  5457. if (result.Arguments.Count != args.Length) return 1;
  5458. for (int i = 0; i < args.Length; i++)
  5459. {
  5460. if (result.Arguments[i] != args[i]) return 1;
  5461. }
  5462. return 0;
  5463. }
  5464. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  5465. {
  5466. if (!(result.BindingType == bt)) return 1;
  5467. if (!(result.Expression == expr)) return 1;
  5468. if (!(result.Member.Equals(member))) return 1;
  5469. if (!(result.ToString() == str))
  5470. {
  5471. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5472. return 1;
  5473. }
  5474. return 0;
  5475. }
  5476. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  5477. {
  5478. if (!(result.BindingType == bt)) return 1;
  5479. if (!(result.Member.Equals(member))) return 1;
  5480. if (!(result.ToString() == str))
  5481. {
  5482. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5483. return 1;
  5484. }
  5485. if (result.Initializers.Count != initializers.Length) return 1;
  5486. for (int i = 0; i < initializers.Length; i++)
  5487. {
  5488. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  5489. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  5490. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  5491. {
  5492. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  5493. }
  5494. }
  5495. return 0;
  5496. }
  5497. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  5498. {
  5499. if (!(result.BindingType == bt)) return 1;
  5500. if (!(result.Member.Equals(member))) return 1;
  5501. if (!(result.ToString() == str))
  5502. {
  5503. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5504. return 1;
  5505. }
  5506. if (result.Bindings.Count != bindings.Length) return 1;
  5507. for (int i = 0; i < bindings.Length; i++)
  5508. {
  5509. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  5510. }
  5511. return 0;
  5512. }
  5513. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  5514. {
  5515. if (!(result.NodeType == et))
  5516. {
  5517. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5518. return 1;
  5519. }
  5520. if (!(result.Type == type))
  5521. {
  5522. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5523. return 1;
  5524. }
  5525. if (!(result.NewExpression.Equals(newExpr))) return 1;
  5526. if (!(result.ToString() == str)) return 1;
  5527. if (result.Bindings.Count != bindings.Length) return 1;
  5528. for (int i = 0; i < bindings.Length; i++)
  5529. {
  5530. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  5531. }
  5532. return 0;
  5533. }
  5534. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  5535. {
  5536. if (!(result.NodeType == et))
  5537. {
  5538. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5539. return 1;
  5540. }
  5541. if (!(result.Type == type))
  5542. {
  5543. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5544. return 1;
  5545. }
  5546. if (result.Expressions.Count != expr.Length) return 1;
  5547. for (int i = 0; i < expr.Length; i++)
  5548. {
  5549. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  5550. }
  5551. if (!(result.ToString() == str))
  5552. {
  5553. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5554. return 1;
  5555. }
  5556. return 0;
  5557. }
  5558. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  5559. {
  5560. if (!(result.NodeType == et))
  5561. {
  5562. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5563. return 1;
  5564. }
  5565. if (!(result.Type == type))
  5566. {
  5567. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5568. return 1;
  5569. }
  5570. if (!(result.Name == name)) return 1;
  5571. if (!(result.ToString() == str))
  5572. {
  5573. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5574. return 1;
  5575. }
  5576. return 0;
  5577. }
  5578. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  5579. {
  5580. if (!(result.NodeType == et))
  5581. {
  5582. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5583. return 1;
  5584. }
  5585. if (!(result.Type == type))
  5586. {
  5587. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5588. return 1;
  5589. }
  5590. if (expr == null)
  5591. {
  5592. if (result.Body != null) return 1;
  5593. }
  5594. else
  5595. {
  5596. if (!(result.Body.Equals(expr))) return 1;
  5597. }
  5598. if (result.Parameters.Count != parms.Length) return 1;
  5599. for (int i = 0; i < parms.Length; i++)
  5600. {
  5601. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  5602. }
  5603. if (!(result.ToString() == str))
  5604. {
  5605. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  5606. return 1;
  5607. }
  5608. return 0;
  5609. }
  5610. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  5611. {
  5612. if (!(result.NodeType == et))
  5613. {
  5614. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5615. return 1;
  5616. }
  5617. if (!(result.Type == type))
  5618. {
  5619. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5620. return 1;
  5621. }
  5622. if (expr == null)
  5623. {
  5624. if (result.Expression != null) return 1;
  5625. }
  5626. else
  5627. {
  5628. if (!(result.Expression.Equals(expr))) return 1;
  5629. }
  5630. if (result.Arguments.Count != args.Length) return 1;
  5631. for (int i = 0; i < args.Length; i++)
  5632. {
  5633. if (!(result.Arguments[i].Equals(args[i])))
  5634. {
  5635. return 1;
  5636. }
  5637. }
  5638. if (result.ToString() != str)
  5639. {
  5640. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5641. return 1;
  5642. }
  5643. return 0;
  5644. }
  5645. }
  5646. namespace Not
  5647. {
  5648. // Declaring user-defined types for testing
  5649. struct TC1
  5650. {
  5651. public static TC1 operator !(TC1 c)
  5652. {
  5653. return new TC1();
  5654. }
  5655. public static TC1 operator ~(TC1 c)
  5656. {
  5657. return new TC1();
  5658. }
  5659. }
  5660. struct TC2
  5661. {
  5662. public static TC2 operator ~(TC2 c)
  5663. {
  5664. return new TC2();
  5665. }
  5666. }
  5667. struct TC3
  5668. {
  5669. public static TC3 Meth1(TC3 c)
  5670. {
  5671. return new TC3();
  5672. }
  5673. }
  5674. }
  5675. }
  5676. //-------- Scenario 790
  5677. namespace Scenario790
  5678. {
  5679. namespace Not
  5680. {
  5681. public class Test
  5682. {
  5683. // Overload-1: Test for functionality: Argument is of type user-defined type (Bitwise Complement)
  5684. public static int Test9()
  5685. {
  5686. TC2 ctest = new TC2();
  5687. ConstantExpression ce = Expression.Constant(ctest, typeof(TC2));
  5688. Type exp_type = typeof(TC2);
  5689. ExpressionType exp_et = ExpressionType.Not;
  5690. string exp_str = "Not(" + ce.ToString() + ")";
  5691. Expression exp_operand = ce;
  5692. MethodInfo exp_mi = typeof(TC2).GetMethod("op_OnesComplement");
  5693. UnaryExpression result = Expression.Not(ce);
  5694. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, false, false);
  5695. }
  5696. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not9__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  5697. public static Expression Not9__()
  5698. {
  5699. if (Main() != 0)
  5700. {
  5701. throw new Exception();
  5702. }
  5703. else
  5704. {
  5705. return Expression.Constant(0);
  5706. }
  5707. }
  5708. public static int Main()
  5709. {
  5710. return Test9();
  5711. }
  5712. }
  5713. }
  5714. public static class Extension
  5715. {
  5716. public static bool CompareParamName(this ArgumentException ex, string expected)
  5717. {
  5718. #if SILVERLIGHT
  5719. #if SLRESOURCES
  5720. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  5721. #else
  5722. return true;
  5723. #endif
  5724. #else
  5725. return ex.ParamName == expected;
  5726. #endif
  5727. }
  5728. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  5729. {
  5730. #if SILVERLIGHT
  5731. #if SLRESOURCES
  5732. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  5733. #else
  5734. return true;
  5735. #endif
  5736. #else
  5737. return ex.ParamName == expected;
  5738. #endif
  5739. }
  5740. }
  5741. public static class Verification
  5742. {
  5743. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  5744. {
  5745. if (!(result.NodeType == et))
  5746. {
  5747. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5748. return 1;
  5749. }
  5750. if (!(result.Type == type))
  5751. {
  5752. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5753. return 1;
  5754. }
  5755. if (val == null)
  5756. {
  5757. if (result.Value != null) return 1;
  5758. }
  5759. else
  5760. {
  5761. if (!(result.Value.Equals(val))) return 1;
  5762. }
  5763. if (!(result.ToString() == str)) return 1;
  5764. return 0;
  5765. }
  5766. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  5767. {
  5768. if (!(result.NodeType == et))
  5769. {
  5770. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5771. return 1;
  5772. }
  5773. if (!(result.Type == type))
  5774. {
  5775. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5776. return 1;
  5777. }
  5778. if (operand == null)
  5779. {
  5780. if (result.Operand != null) return 1;
  5781. }
  5782. else
  5783. {
  5784. if (!(result.Operand.Equals(operand))) return 1;
  5785. }
  5786. if (!(result.ToString() == str))
  5787. {
  5788. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5789. return 1;
  5790. }
  5791. if (result.Method != mi) return 1;
  5792. if (result.IsLifted != islifted) return 1;
  5793. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5794. return 0;
  5795. }
  5796. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  5797. {
  5798. if (!(result.NodeType == et))
  5799. {
  5800. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5801. return 1;
  5802. }
  5803. if (!(result.Type == type))
  5804. {
  5805. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5806. return 1;
  5807. }
  5808. if (left == null)
  5809. {
  5810. if (result.Left != null)
  5811. {
  5812. Console.WriteLine("left was null");
  5813. return 1;
  5814. }
  5815. }
  5816. else
  5817. {
  5818. if (!(result.Left.Equals(left)))
  5819. {
  5820. Console.WriteLine("left was different");
  5821. return 1;
  5822. }
  5823. }
  5824. if (right == null)
  5825. {
  5826. if (result.Right != null) return 1;
  5827. }
  5828. else
  5829. {
  5830. if (!(result.Right.Equals(right))) return 1;
  5831. }
  5832. if (!(result.ToString() == str))
  5833. {
  5834. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5835. return 1;
  5836. }
  5837. if (result.Method != mi) return 1;
  5838. if (result.IsLifted != islifted) return 1;
  5839. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5840. if (result.Conversion != null) return 1;
  5841. return 0;
  5842. }
  5843. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  5844. {
  5845. if (!(result.NodeType == et))
  5846. {
  5847. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5848. return 1;
  5849. }
  5850. if (!(result.Type == type))
  5851. {
  5852. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5853. return 1;
  5854. }
  5855. if (left == null)
  5856. {
  5857. if (result.Left != null) return 1;
  5858. }
  5859. else
  5860. {
  5861. if (!(result.Left.Equals(left))) return 1;
  5862. }
  5863. if (right == null)
  5864. {
  5865. if (result.Right != null) return 1;
  5866. }
  5867. else
  5868. {
  5869. if (!(result.Right.Equals(right))) return 1;
  5870. }
  5871. if (!(result.ToString() == str)) return 1;
  5872. if (result.Method != mi) return 1;
  5873. if (result.IsLifted != islifted) return 1;
  5874. if (result.IsLiftedToNull != isliftedtonull) return 1;
  5875. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  5876. return 0;
  5877. }
  5878. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  5879. {
  5880. if (!(result.NodeType == et))
  5881. {
  5882. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5883. return 1;
  5884. }
  5885. if (!(result.Type == type))
  5886. {
  5887. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5888. return 1;
  5889. }
  5890. if (!(result.Method == method)) return 1;
  5891. if (obj == null)
  5892. {
  5893. if (result.Object != null)
  5894. {
  5895. Console.WriteLine("Expected object to be null.");
  5896. return 1;
  5897. }
  5898. }
  5899. else
  5900. {
  5901. if (!(result.Object.Equals(obj)))
  5902. {
  5903. Console.WriteLine("Object on which call is made is different from the result.");
  5904. return 1;
  5905. }
  5906. }
  5907. if (!(result.ToString() == str))
  5908. {
  5909. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5910. return 1;
  5911. }
  5912. if (result.Arguments.Count != arguments.Length) return 1;
  5913. for (int i = 0; i < arguments.Length; i++)
  5914. {
  5915. if (result.Arguments[i] != arguments[i]) return 1;
  5916. }
  5917. return 0;
  5918. }
  5919. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  5920. {
  5921. if (!(result.NodeType == et))
  5922. {
  5923. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5924. return 1;
  5925. }
  5926. if (!(result.Type == type))
  5927. {
  5928. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5929. return 1;
  5930. }
  5931. if (expr == null)
  5932. {
  5933. Console.WriteLine("expr was null.");
  5934. if (result.Expression != null) return 1;
  5935. }
  5936. else
  5937. {
  5938. if (!(result.Expression.Equals(expr)))
  5939. {
  5940. return 1;
  5941. }
  5942. }
  5943. if (!(result.TypeOperand == typeop)) return 1;
  5944. if (!(result.ToString() == str))
  5945. {
  5946. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  5947. return 1;
  5948. }
  5949. return 0;
  5950. }
  5951. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  5952. {
  5953. if (!(result.NodeType == et))
  5954. {
  5955. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5956. return 1;
  5957. }
  5958. if (!(result.Type == type))
  5959. {
  5960. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  5961. return 1;
  5962. }
  5963. if (test == null)
  5964. {
  5965. if (result.Test != null) return 1;
  5966. }
  5967. else
  5968. {
  5969. if (!(result.Test.Equals(test))) return 1;
  5970. }
  5971. if (ifTrue == null)
  5972. {
  5973. if (result.IfTrue != null) return 1;
  5974. }
  5975. else
  5976. {
  5977. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  5978. }
  5979. if (ifFalse == null)
  5980. {
  5981. if (result.IfFalse != null) return 1;
  5982. }
  5983. else
  5984. {
  5985. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  5986. }
  5987. if (!(result.ToString() == str)) return 1;
  5988. return 0;
  5989. }
  5990. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  5991. {
  5992. if (!(result.NodeType == et))
  5993. {
  5994. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  5995. return 1;
  5996. }
  5997. if (!(result.Type == type))
  5998. {
  5999. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6000. return 1;
  6001. }
  6002. if (exp_expr == null)
  6003. {
  6004. if (result.Expression != null)
  6005. {
  6006. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  6007. return 1;
  6008. }
  6009. }
  6010. else
  6011. {
  6012. if (!(result.Expression.Equals(exp_expr)))
  6013. {
  6014. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  6015. return 1;
  6016. }
  6017. }
  6018. if (!(result.Member == exp_member))
  6019. {
  6020. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  6021. return 1;
  6022. }
  6023. if (!(result.ToString() == str))
  6024. {
  6025. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6026. return 1;
  6027. }
  6028. return 0;
  6029. }
  6030. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  6031. {
  6032. if (!(result.NodeType == et))
  6033. {
  6034. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6035. return 1;
  6036. }
  6037. if (!(result.Type == type))
  6038. {
  6039. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6040. return 1;
  6041. }
  6042. if (!(result.Constructor == constructor))
  6043. {
  6044. Console.WriteLine("Unexpected constructor");
  6045. return 1;
  6046. }
  6047. if (!(result.ToString() == str))
  6048. {
  6049. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6050. return 1;
  6051. }
  6052. if (arguments == null)
  6053. {
  6054. if (result.Arguments.Count != 0)
  6055. {
  6056. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  6057. return 1;
  6058. }
  6059. }
  6060. else
  6061. {
  6062. if (result.Arguments.Count != arguments.Length)
  6063. {
  6064. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  6065. return 1;
  6066. }
  6067. for (int i = 0; i < arguments.Length; i++)
  6068. {
  6069. if (result.Arguments[i] != arguments[i])
  6070. {
  6071. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  6072. return 1;
  6073. }
  6074. }
  6075. }
  6076. if (result.Members == null)
  6077. {
  6078. Console.WriteLine("result.Members was null");
  6079. return 1;
  6080. }
  6081. if (members == null)
  6082. {
  6083. if (result.Members.Count != 0)
  6084. {
  6085. Console.WriteLine("Got more than zero members");
  6086. return 1;
  6087. }
  6088. }
  6089. else
  6090. {
  6091. if (result.Members.Count != members.Length)
  6092. {
  6093. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  6094. return 1;
  6095. }
  6096. for (int i = 0; i < members.Length; i++)
  6097. {
  6098. if (result.Members[i] != members[i])
  6099. {
  6100. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  6101. return 1;
  6102. }
  6103. }
  6104. }
  6105. return 0;
  6106. }
  6107. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  6108. {
  6109. if (!(result.NodeType == et))
  6110. {
  6111. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6112. return 1;
  6113. }
  6114. if (!(result.Type == type))
  6115. {
  6116. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6117. return 1;
  6118. }
  6119. if (!(result.Constructor == constructor))
  6120. {
  6121. Console.WriteLine("Constructor is different from expected.");
  6122. return 1;
  6123. }
  6124. if (!(result.ToString() == str))
  6125. {
  6126. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6127. return 1;
  6128. }
  6129. if (result.Arguments.Count != arguments.Length)
  6130. {
  6131. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  6132. return 1;
  6133. }
  6134. for (int i = 0; i < arguments.Length; i++)
  6135. {
  6136. if (result.Arguments[i] != arguments[i])
  6137. {
  6138. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  6139. return 1;
  6140. }
  6141. }
  6142. if (result.Members != null)
  6143. {
  6144. Console.WriteLine("result.Members isn't null");
  6145. return 1;
  6146. }
  6147. return 0;
  6148. }
  6149. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  6150. {
  6151. if (!(result.NodeType == et))
  6152. {
  6153. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6154. return 1;
  6155. }
  6156. if (!(result.Type == type))
  6157. {
  6158. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6159. return 1;
  6160. }
  6161. if (!(result.NewExpression == newExpression)) return 1;
  6162. if (!(result.ToString() == str))
  6163. {
  6164. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6165. return 1;
  6166. }
  6167. if (result.Initializers.Count != initializers.Length) return 1;
  6168. for (int i = 0; i < initializers.Length; i++)
  6169. {
  6170. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  6171. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  6172. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  6173. {
  6174. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  6175. }
  6176. }
  6177. return 0;
  6178. }
  6179. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  6180. {
  6181. if (result.AddMethod != exp_mi) return 1;
  6182. if (!(result.ToString() == str))
  6183. {
  6184. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6185. return 1;
  6186. }
  6187. if (result.Arguments.Count != args.Length) return 1;
  6188. for (int i = 0; i < args.Length; i++)
  6189. {
  6190. if (result.Arguments[i] != args[i]) return 1;
  6191. }
  6192. return 0;
  6193. }
  6194. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  6195. {
  6196. if (!(result.BindingType == bt)) return 1;
  6197. if (!(result.Expression == expr)) return 1;
  6198. if (!(result.Member.Equals(member))) return 1;
  6199. if (!(result.ToString() == str))
  6200. {
  6201. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6202. return 1;
  6203. }
  6204. return 0;
  6205. }
  6206. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  6207. {
  6208. if (!(result.BindingType == bt)) return 1;
  6209. if (!(result.Member.Equals(member))) return 1;
  6210. if (!(result.ToString() == str))
  6211. {
  6212. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6213. return 1;
  6214. }
  6215. if (result.Initializers.Count != initializers.Length) return 1;
  6216. for (int i = 0; i < initializers.Length; i++)
  6217. {
  6218. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  6219. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  6220. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  6221. {
  6222. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  6223. }
  6224. }
  6225. return 0;
  6226. }
  6227. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  6228. {
  6229. if (!(result.BindingType == bt)) return 1;
  6230. if (!(result.Member.Equals(member))) return 1;
  6231. if (!(result.ToString() == str))
  6232. {
  6233. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6234. return 1;
  6235. }
  6236. if (result.Bindings.Count != bindings.Length) return 1;
  6237. for (int i = 0; i < bindings.Length; i++)
  6238. {
  6239. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  6240. }
  6241. return 0;
  6242. }
  6243. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  6244. {
  6245. if (!(result.NodeType == et))
  6246. {
  6247. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6248. return 1;
  6249. }
  6250. if (!(result.Type == type))
  6251. {
  6252. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6253. return 1;
  6254. }
  6255. if (!(result.NewExpression.Equals(newExpr))) return 1;
  6256. if (!(result.ToString() == str)) return 1;
  6257. if (result.Bindings.Count != bindings.Length) return 1;
  6258. for (int i = 0; i < bindings.Length; i++)
  6259. {
  6260. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  6261. }
  6262. return 0;
  6263. }
  6264. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  6265. {
  6266. if (!(result.NodeType == et))
  6267. {
  6268. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6269. return 1;
  6270. }
  6271. if (!(result.Type == type))
  6272. {
  6273. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6274. return 1;
  6275. }
  6276. if (result.Expressions.Count != expr.Length) return 1;
  6277. for (int i = 0; i < expr.Length; i++)
  6278. {
  6279. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  6280. }
  6281. if (!(result.ToString() == str))
  6282. {
  6283. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6284. return 1;
  6285. }
  6286. return 0;
  6287. }
  6288. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  6289. {
  6290. if (!(result.NodeType == et))
  6291. {
  6292. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6293. return 1;
  6294. }
  6295. if (!(result.Type == type))
  6296. {
  6297. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6298. return 1;
  6299. }
  6300. if (!(result.Name == name)) return 1;
  6301. if (!(result.ToString() == str))
  6302. {
  6303. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6304. return 1;
  6305. }
  6306. return 0;
  6307. }
  6308. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  6309. {
  6310. if (!(result.NodeType == et))
  6311. {
  6312. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6313. return 1;
  6314. }
  6315. if (!(result.Type == type))
  6316. {
  6317. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6318. return 1;
  6319. }
  6320. if (expr == null)
  6321. {
  6322. if (result.Body != null) return 1;
  6323. }
  6324. else
  6325. {
  6326. if (!(result.Body.Equals(expr))) return 1;
  6327. }
  6328. if (result.Parameters.Count != parms.Length) return 1;
  6329. for (int i = 0; i < parms.Length; i++)
  6330. {
  6331. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  6332. }
  6333. if (!(result.ToString() == str))
  6334. {
  6335. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6336. return 1;
  6337. }
  6338. return 0;
  6339. }
  6340. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  6341. {
  6342. if (!(result.NodeType == et))
  6343. {
  6344. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6345. return 1;
  6346. }
  6347. if (!(result.Type == type))
  6348. {
  6349. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6350. return 1;
  6351. }
  6352. if (expr == null)
  6353. {
  6354. if (result.Expression != null) return 1;
  6355. }
  6356. else
  6357. {
  6358. if (!(result.Expression.Equals(expr))) return 1;
  6359. }
  6360. if (result.Arguments.Count != args.Length) return 1;
  6361. for (int i = 0; i < args.Length; i++)
  6362. {
  6363. if (!(result.Arguments[i].Equals(args[i])))
  6364. {
  6365. return 1;
  6366. }
  6367. }
  6368. if (result.ToString() != str)
  6369. {
  6370. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  6371. return 1;
  6372. }
  6373. return 0;
  6374. }
  6375. }
  6376. namespace Not
  6377. {
  6378. // Declaring user-defined types for testing
  6379. struct TC1
  6380. {
  6381. public static TC1 operator !(TC1 c)
  6382. {
  6383. return new TC1();
  6384. }
  6385. public static TC1 operator ~(TC1 c)
  6386. {
  6387. return new TC1();
  6388. }
  6389. }
  6390. struct TC2
  6391. {
  6392. public static TC2 operator ~(TC2 c)
  6393. {
  6394. return new TC2();
  6395. }
  6396. }
  6397. struct TC3
  6398. {
  6399. public static TC3 Meth1(TC3 c)
  6400. {
  6401. return new TC3();
  6402. }
  6403. }
  6404. }
  6405. }
  6406. //-------- Scenario 791
  6407. namespace Scenario791
  6408. {
  6409. namespace Not
  6410. {
  6411. public class Test
  6412. {
  6413. // Overload-1: Test for functionality: Argument is of type nullable user-defined type (Logical Not)
  6414. public static int Test10()
  6415. {
  6416. TC2? ctest = new TC2?();
  6417. ConstantExpression ce = Expression.Constant(ctest, typeof(TC2?));
  6418. Type exp_type = typeof(TC2?);
  6419. ExpressionType exp_et = ExpressionType.Not;
  6420. string exp_str = "Not(" + ce.ToString() + ")";
  6421. Expression exp_operand = ce;
  6422. MethodInfo exp_mi = typeof(TC2).GetMethod("op_OnesComplement");
  6423. UnaryExpression result = Expression.Not(ce);
  6424. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, true, true);
  6425. }
  6426. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not10__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  6427. public static Expression Not10__()
  6428. {
  6429. if (Main() != 0)
  6430. {
  6431. throw new Exception();
  6432. }
  6433. else
  6434. {
  6435. return Expression.Constant(0);
  6436. }
  6437. }
  6438. public static int Main()
  6439. {
  6440. return Test10();
  6441. }
  6442. }
  6443. }
  6444. public static class Extension
  6445. {
  6446. public static bool CompareParamName(this ArgumentException ex, string expected)
  6447. {
  6448. #if SILVERLIGHT
  6449. #if SLRESOURCES
  6450. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  6451. #else
  6452. return true;
  6453. #endif
  6454. #else
  6455. return ex.ParamName == expected;
  6456. #endif
  6457. }
  6458. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  6459. {
  6460. #if SILVERLIGHT
  6461. #if SLRESOURCES
  6462. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  6463. #else
  6464. return true;
  6465. #endif
  6466. #else
  6467. return ex.ParamName == expected;
  6468. #endif
  6469. }
  6470. }
  6471. public static class Verification
  6472. {
  6473. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  6474. {
  6475. if (!(result.NodeType == et))
  6476. {
  6477. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6478. return 1;
  6479. }
  6480. if (!(result.Type == type))
  6481. {
  6482. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6483. return 1;
  6484. }
  6485. if (val == null)
  6486. {
  6487. if (result.Value != null) return 1;
  6488. }
  6489. else
  6490. {
  6491. if (!(result.Value.Equals(val))) return 1;
  6492. }
  6493. if (!(result.ToString() == str)) return 1;
  6494. return 0;
  6495. }
  6496. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  6497. {
  6498. if (!(result.NodeType == et))
  6499. {
  6500. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6501. return 1;
  6502. }
  6503. if (!(result.Type == type))
  6504. {
  6505. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6506. return 1;
  6507. }
  6508. if (operand == null)
  6509. {
  6510. if (result.Operand != null) return 1;
  6511. }
  6512. else
  6513. {
  6514. if (!(result.Operand.Equals(operand))) return 1;
  6515. }
  6516. if (!(result.ToString() == str))
  6517. {
  6518. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  6519. return 1;
  6520. }
  6521. if (result.Method != mi) return 1;
  6522. if (result.IsLifted != islifted) return 1;
  6523. if (result.IsLiftedToNull != isliftedtonull) return 1;
  6524. return 0;
  6525. }
  6526. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  6527. {
  6528. if (!(result.NodeType == et))
  6529. {
  6530. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6531. return 1;
  6532. }
  6533. if (!(result.Type == type))
  6534. {
  6535. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6536. return 1;
  6537. }
  6538. if (left == null)
  6539. {
  6540. if (result.Left != null)
  6541. {
  6542. Console.WriteLine("left was null");
  6543. return 1;
  6544. }
  6545. }
  6546. else
  6547. {
  6548. if (!(result.Left.Equals(left)))
  6549. {
  6550. Console.WriteLine("left was different");
  6551. return 1;
  6552. }
  6553. }
  6554. if (right == null)
  6555. {
  6556. if (result.Right != null) return 1;
  6557. }
  6558. else
  6559. {
  6560. if (!(result.Right.Equals(right))) return 1;
  6561. }
  6562. if (!(result.ToString() == str))
  6563. {
  6564. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  6565. return 1;
  6566. }
  6567. if (result.Method != mi) return 1;
  6568. if (result.IsLifted != islifted) return 1;
  6569. if (result.IsLiftedToNull != isliftedtonull) return 1;
  6570. if (result.Conversion != null) return 1;
  6571. return 0;
  6572. }
  6573. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  6574. {
  6575. if (!(result.NodeType == et))
  6576. {
  6577. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6578. return 1;
  6579. }
  6580. if (!(result.Type == type))
  6581. {
  6582. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6583. return 1;
  6584. }
  6585. if (left == null)
  6586. {
  6587. if (result.Left != null) return 1;
  6588. }
  6589. else
  6590. {
  6591. if (!(result.Left.Equals(left))) return 1;
  6592. }
  6593. if (right == null)
  6594. {
  6595. if (result.Right != null) return 1;
  6596. }
  6597. else
  6598. {
  6599. if (!(result.Right.Equals(right))) return 1;
  6600. }
  6601. if (!(result.ToString() == str)) return 1;
  6602. if (result.Method != mi) return 1;
  6603. if (result.IsLifted != islifted) return 1;
  6604. if (result.IsLiftedToNull != isliftedtonull) return 1;
  6605. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  6606. return 0;
  6607. }
  6608. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  6609. {
  6610. if (!(result.NodeType == et))
  6611. {
  6612. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6613. return 1;
  6614. }
  6615. if (!(result.Type == type))
  6616. {
  6617. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6618. return 1;
  6619. }
  6620. if (!(result.Method == method)) return 1;
  6621. if (obj == null)
  6622. {
  6623. if (result.Object != null)
  6624. {
  6625. Console.WriteLine("Expected object to be null.");
  6626. return 1;
  6627. }
  6628. }
  6629. else
  6630. {
  6631. if (!(result.Object.Equals(obj)))
  6632. {
  6633. Console.WriteLine("Object on which call is made is different from the result.");
  6634. return 1;
  6635. }
  6636. }
  6637. if (!(result.ToString() == str))
  6638. {
  6639. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  6640. return 1;
  6641. }
  6642. if (result.Arguments.Count != arguments.Length) return 1;
  6643. for (int i = 0; i < arguments.Length; i++)
  6644. {
  6645. if (result.Arguments[i] != arguments[i]) return 1;
  6646. }
  6647. return 0;
  6648. }
  6649. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  6650. {
  6651. if (!(result.NodeType == et))
  6652. {
  6653. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6654. return 1;
  6655. }
  6656. if (!(result.Type == type))
  6657. {
  6658. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6659. return 1;
  6660. }
  6661. if (expr == null)
  6662. {
  6663. Console.WriteLine("expr was null.");
  6664. if (result.Expression != null) return 1;
  6665. }
  6666. else
  6667. {
  6668. if (!(result.Expression.Equals(expr)))
  6669. {
  6670. return 1;
  6671. }
  6672. }
  6673. if (!(result.TypeOperand == typeop)) return 1;
  6674. if (!(result.ToString() == str))
  6675. {
  6676. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  6677. return 1;
  6678. }
  6679. return 0;
  6680. }
  6681. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  6682. {
  6683. if (!(result.NodeType == et))
  6684. {
  6685. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6686. return 1;
  6687. }
  6688. if (!(result.Type == type))
  6689. {
  6690. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6691. return 1;
  6692. }
  6693. if (test == null)
  6694. {
  6695. if (result.Test != null) return 1;
  6696. }
  6697. else
  6698. {
  6699. if (!(result.Test.Equals(test))) return 1;
  6700. }
  6701. if (ifTrue == null)
  6702. {
  6703. if (result.IfTrue != null) return 1;
  6704. }
  6705. else
  6706. {
  6707. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  6708. }
  6709. if (ifFalse == null)
  6710. {
  6711. if (result.IfFalse != null) return 1;
  6712. }
  6713. else
  6714. {
  6715. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  6716. }
  6717. if (!(result.ToString() == str)) return 1;
  6718. return 0;
  6719. }
  6720. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  6721. {
  6722. if (!(result.NodeType == et))
  6723. {
  6724. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6725. return 1;
  6726. }
  6727. if (!(result.Type == type))
  6728. {
  6729. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6730. return 1;
  6731. }
  6732. if (exp_expr == null)
  6733. {
  6734. if (result.Expression != null)
  6735. {
  6736. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  6737. return 1;
  6738. }
  6739. }
  6740. else
  6741. {
  6742. if (!(result.Expression.Equals(exp_expr)))
  6743. {
  6744. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  6745. return 1;
  6746. }
  6747. }
  6748. if (!(result.Member == exp_member))
  6749. {
  6750. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  6751. return 1;
  6752. }
  6753. if (!(result.ToString() == str))
  6754. {
  6755. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6756. return 1;
  6757. }
  6758. return 0;
  6759. }
  6760. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  6761. {
  6762. if (!(result.NodeType == et))
  6763. {
  6764. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6765. return 1;
  6766. }
  6767. if (!(result.Type == type))
  6768. {
  6769. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6770. return 1;
  6771. }
  6772. if (!(result.Constructor == constructor))
  6773. {
  6774. Console.WriteLine("Unexpected constructor");
  6775. return 1;
  6776. }
  6777. if (!(result.ToString() == str))
  6778. {
  6779. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6780. return 1;
  6781. }
  6782. if (arguments == null)
  6783. {
  6784. if (result.Arguments.Count != 0)
  6785. {
  6786. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  6787. return 1;
  6788. }
  6789. }
  6790. else
  6791. {
  6792. if (result.Arguments.Count != arguments.Length)
  6793. {
  6794. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  6795. return 1;
  6796. }
  6797. for (int i = 0; i < arguments.Length; i++)
  6798. {
  6799. if (result.Arguments[i] != arguments[i])
  6800. {
  6801. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  6802. return 1;
  6803. }
  6804. }
  6805. }
  6806. if (result.Members == null)
  6807. {
  6808. Console.WriteLine("result.Members was null");
  6809. return 1;
  6810. }
  6811. if (members == null)
  6812. {
  6813. if (result.Members.Count != 0)
  6814. {
  6815. Console.WriteLine("Got more than zero members");
  6816. return 1;
  6817. }
  6818. }
  6819. else
  6820. {
  6821. if (result.Members.Count != members.Length)
  6822. {
  6823. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  6824. return 1;
  6825. }
  6826. for (int i = 0; i < members.Length; i++)
  6827. {
  6828. if (result.Members[i] != members[i])
  6829. {
  6830. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  6831. return 1;
  6832. }
  6833. }
  6834. }
  6835. return 0;
  6836. }
  6837. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  6838. {
  6839. if (!(result.NodeType == et))
  6840. {
  6841. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6842. return 1;
  6843. }
  6844. if (!(result.Type == type))
  6845. {
  6846. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6847. return 1;
  6848. }
  6849. if (!(result.Constructor == constructor))
  6850. {
  6851. Console.WriteLine("Constructor is different from expected.");
  6852. return 1;
  6853. }
  6854. if (!(result.ToString() == str))
  6855. {
  6856. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6857. return 1;
  6858. }
  6859. if (result.Arguments.Count != arguments.Length)
  6860. {
  6861. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  6862. return 1;
  6863. }
  6864. for (int i = 0; i < arguments.Length; i++)
  6865. {
  6866. if (result.Arguments[i] != arguments[i])
  6867. {
  6868. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  6869. return 1;
  6870. }
  6871. }
  6872. if (result.Members != null)
  6873. {
  6874. Console.WriteLine("result.Members isn't null");
  6875. return 1;
  6876. }
  6877. return 0;
  6878. }
  6879. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  6880. {
  6881. if (!(result.NodeType == et))
  6882. {
  6883. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6884. return 1;
  6885. }
  6886. if (!(result.Type == type))
  6887. {
  6888. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6889. return 1;
  6890. }
  6891. if (!(result.NewExpression == newExpression)) return 1;
  6892. if (!(result.ToString() == str))
  6893. {
  6894. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6895. return 1;
  6896. }
  6897. if (result.Initializers.Count != initializers.Length) return 1;
  6898. for (int i = 0; i < initializers.Length; i++)
  6899. {
  6900. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  6901. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  6902. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  6903. {
  6904. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  6905. }
  6906. }
  6907. return 0;
  6908. }
  6909. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  6910. {
  6911. if (result.AddMethod != exp_mi) return 1;
  6912. if (!(result.ToString() == str))
  6913. {
  6914. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6915. return 1;
  6916. }
  6917. if (result.Arguments.Count != args.Length) return 1;
  6918. for (int i = 0; i < args.Length; i++)
  6919. {
  6920. if (result.Arguments[i] != args[i]) return 1;
  6921. }
  6922. return 0;
  6923. }
  6924. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  6925. {
  6926. if (!(result.BindingType == bt)) return 1;
  6927. if (!(result.Expression == expr)) return 1;
  6928. if (!(result.Member.Equals(member))) return 1;
  6929. if (!(result.ToString() == str))
  6930. {
  6931. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6932. return 1;
  6933. }
  6934. return 0;
  6935. }
  6936. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  6937. {
  6938. if (!(result.BindingType == bt)) return 1;
  6939. if (!(result.Member.Equals(member))) return 1;
  6940. if (!(result.ToString() == str))
  6941. {
  6942. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6943. return 1;
  6944. }
  6945. if (result.Initializers.Count != initializers.Length) return 1;
  6946. for (int i = 0; i < initializers.Length; i++)
  6947. {
  6948. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  6949. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  6950. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  6951. {
  6952. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  6953. }
  6954. }
  6955. return 0;
  6956. }
  6957. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  6958. {
  6959. if (!(result.BindingType == bt)) return 1;
  6960. if (!(result.Member.Equals(member))) return 1;
  6961. if (!(result.ToString() == str))
  6962. {
  6963. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  6964. return 1;
  6965. }
  6966. if (result.Bindings.Count != bindings.Length) return 1;
  6967. for (int i = 0; i < bindings.Length; i++)
  6968. {
  6969. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  6970. }
  6971. return 0;
  6972. }
  6973. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  6974. {
  6975. if (!(result.NodeType == et))
  6976. {
  6977. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6978. return 1;
  6979. }
  6980. if (!(result.Type == type))
  6981. {
  6982. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  6983. return 1;
  6984. }
  6985. if (!(result.NewExpression.Equals(newExpr))) return 1;
  6986. if (!(result.ToString() == str)) return 1;
  6987. if (result.Bindings.Count != bindings.Length) return 1;
  6988. for (int i = 0; i < bindings.Length; i++)
  6989. {
  6990. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  6991. }
  6992. return 0;
  6993. }
  6994. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  6995. {
  6996. if (!(result.NodeType == et))
  6997. {
  6998. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  6999. return 1;
  7000. }
  7001. if (!(result.Type == type))
  7002. {
  7003. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7004. return 1;
  7005. }
  7006. if (result.Expressions.Count != expr.Length) return 1;
  7007. for (int i = 0; i < expr.Length; i++)
  7008. {
  7009. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  7010. }
  7011. if (!(result.ToString() == str))
  7012. {
  7013. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7014. return 1;
  7015. }
  7016. return 0;
  7017. }
  7018. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  7019. {
  7020. if (!(result.NodeType == et))
  7021. {
  7022. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7023. return 1;
  7024. }
  7025. if (!(result.Type == type))
  7026. {
  7027. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7028. return 1;
  7029. }
  7030. if (!(result.Name == name)) return 1;
  7031. if (!(result.ToString() == str))
  7032. {
  7033. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7034. return 1;
  7035. }
  7036. return 0;
  7037. }
  7038. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  7039. {
  7040. if (!(result.NodeType == et))
  7041. {
  7042. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7043. return 1;
  7044. }
  7045. if (!(result.Type == type))
  7046. {
  7047. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7048. return 1;
  7049. }
  7050. if (expr == null)
  7051. {
  7052. if (result.Body != null) return 1;
  7053. }
  7054. else
  7055. {
  7056. if (!(result.Body.Equals(expr))) return 1;
  7057. }
  7058. if (result.Parameters.Count != parms.Length) return 1;
  7059. for (int i = 0; i < parms.Length; i++)
  7060. {
  7061. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  7062. }
  7063. if (!(result.ToString() == str))
  7064. {
  7065. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7066. return 1;
  7067. }
  7068. return 0;
  7069. }
  7070. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  7071. {
  7072. if (!(result.NodeType == et))
  7073. {
  7074. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7075. return 1;
  7076. }
  7077. if (!(result.Type == type))
  7078. {
  7079. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7080. return 1;
  7081. }
  7082. if (expr == null)
  7083. {
  7084. if (result.Expression != null) return 1;
  7085. }
  7086. else
  7087. {
  7088. if (!(result.Expression.Equals(expr))) return 1;
  7089. }
  7090. if (result.Arguments.Count != args.Length) return 1;
  7091. for (int i = 0; i < args.Length; i++)
  7092. {
  7093. if (!(result.Arguments[i].Equals(args[i])))
  7094. {
  7095. return 1;
  7096. }
  7097. }
  7098. if (result.ToString() != str)
  7099. {
  7100. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7101. return 1;
  7102. }
  7103. return 0;
  7104. }
  7105. }
  7106. namespace Not
  7107. {
  7108. // Declaring user-defined types for testing
  7109. struct TC1
  7110. {
  7111. public static TC1 operator !(TC1 c)
  7112. {
  7113. return new TC1();
  7114. }
  7115. public static TC1 operator ~(TC1 c)
  7116. {
  7117. return new TC1();
  7118. }
  7119. }
  7120. struct TC2
  7121. {
  7122. public static TC2 operator ~(TC2 c)
  7123. {
  7124. return new TC2();
  7125. }
  7126. }
  7127. struct TC3
  7128. {
  7129. public static TC3 Meth1(TC3 c)
  7130. {
  7131. return new TC3();
  7132. }
  7133. }
  7134. }
  7135. }
  7136. //-------- Scenario 792
  7137. namespace Scenario792
  7138. {
  7139. namespace Not
  7140. {
  7141. public class Test
  7142. {
  7143. // Overload-1: User-defined type without operator overloading
  7144. public static int Test11()
  7145. {
  7146. TC3 ctest = new TC3();
  7147. ConstantExpression ce = Expression.Constant(ctest, typeof(TC3));
  7148. try
  7149. {
  7150. UnaryExpression result = Expression.Not(ce);
  7151. return 1;
  7152. }
  7153. catch (InvalidOperationException)
  7154. {
  7155. return 0;
  7156. }
  7157. }
  7158. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not11__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  7159. public static Expression Not11__()
  7160. {
  7161. if (Main() != 0)
  7162. {
  7163. throw new Exception();
  7164. }
  7165. else
  7166. {
  7167. return Expression.Constant(0);
  7168. }
  7169. }
  7170. public static int Main()
  7171. {
  7172. return Test11();
  7173. }
  7174. }
  7175. }
  7176. public static class Extension
  7177. {
  7178. public static bool CompareParamName(this ArgumentException ex, string expected)
  7179. {
  7180. #if SILVERLIGHT
  7181. #if SLRESOURCES
  7182. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  7183. #else
  7184. return true;
  7185. #endif
  7186. #else
  7187. return ex.ParamName == expected;
  7188. #endif
  7189. }
  7190. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  7191. {
  7192. #if SILVERLIGHT
  7193. #if SLRESOURCES
  7194. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  7195. #else
  7196. return true;
  7197. #endif
  7198. #else
  7199. return ex.ParamName == expected;
  7200. #endif
  7201. }
  7202. }
  7203. public static class Verification
  7204. {
  7205. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  7206. {
  7207. if (!(result.NodeType == et))
  7208. {
  7209. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7210. return 1;
  7211. }
  7212. if (!(result.Type == type))
  7213. {
  7214. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7215. return 1;
  7216. }
  7217. if (val == null)
  7218. {
  7219. if (result.Value != null) return 1;
  7220. }
  7221. else
  7222. {
  7223. if (!(result.Value.Equals(val))) return 1;
  7224. }
  7225. if (!(result.ToString() == str)) return 1;
  7226. return 0;
  7227. }
  7228. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  7229. {
  7230. if (!(result.NodeType == et))
  7231. {
  7232. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7233. return 1;
  7234. }
  7235. if (!(result.Type == type))
  7236. {
  7237. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7238. return 1;
  7239. }
  7240. if (operand == null)
  7241. {
  7242. if (result.Operand != null) return 1;
  7243. }
  7244. else
  7245. {
  7246. if (!(result.Operand.Equals(operand))) return 1;
  7247. }
  7248. if (!(result.ToString() == str))
  7249. {
  7250. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7251. return 1;
  7252. }
  7253. if (result.Method != mi) return 1;
  7254. if (result.IsLifted != islifted) return 1;
  7255. if (result.IsLiftedToNull != isliftedtonull) return 1;
  7256. return 0;
  7257. }
  7258. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  7259. {
  7260. if (!(result.NodeType == et))
  7261. {
  7262. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7263. return 1;
  7264. }
  7265. if (!(result.Type == type))
  7266. {
  7267. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7268. return 1;
  7269. }
  7270. if (left == null)
  7271. {
  7272. if (result.Left != null)
  7273. {
  7274. Console.WriteLine("left was null");
  7275. return 1;
  7276. }
  7277. }
  7278. else
  7279. {
  7280. if (!(result.Left.Equals(left)))
  7281. {
  7282. Console.WriteLine("left was different");
  7283. return 1;
  7284. }
  7285. }
  7286. if (right == null)
  7287. {
  7288. if (result.Right != null) return 1;
  7289. }
  7290. else
  7291. {
  7292. if (!(result.Right.Equals(right))) return 1;
  7293. }
  7294. if (!(result.ToString() == str))
  7295. {
  7296. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7297. return 1;
  7298. }
  7299. if (result.Method != mi) return 1;
  7300. if (result.IsLifted != islifted) return 1;
  7301. if (result.IsLiftedToNull != isliftedtonull) return 1;
  7302. if (result.Conversion != null) return 1;
  7303. return 0;
  7304. }
  7305. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  7306. {
  7307. if (!(result.NodeType == et))
  7308. {
  7309. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7310. return 1;
  7311. }
  7312. if (!(result.Type == type))
  7313. {
  7314. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7315. return 1;
  7316. }
  7317. if (left == null)
  7318. {
  7319. if (result.Left != null) return 1;
  7320. }
  7321. else
  7322. {
  7323. if (!(result.Left.Equals(left))) return 1;
  7324. }
  7325. if (right == null)
  7326. {
  7327. if (result.Right != null) return 1;
  7328. }
  7329. else
  7330. {
  7331. if (!(result.Right.Equals(right))) return 1;
  7332. }
  7333. if (!(result.ToString() == str)) return 1;
  7334. if (result.Method != mi) return 1;
  7335. if (result.IsLifted != islifted) return 1;
  7336. if (result.IsLiftedToNull != isliftedtonull) return 1;
  7337. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  7338. return 0;
  7339. }
  7340. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  7341. {
  7342. if (!(result.NodeType == et))
  7343. {
  7344. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7345. return 1;
  7346. }
  7347. if (!(result.Type == type))
  7348. {
  7349. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7350. return 1;
  7351. }
  7352. if (!(result.Method == method)) return 1;
  7353. if (obj == null)
  7354. {
  7355. if (result.Object != null)
  7356. {
  7357. Console.WriteLine("Expected object to be null.");
  7358. return 1;
  7359. }
  7360. }
  7361. else
  7362. {
  7363. if (!(result.Object.Equals(obj)))
  7364. {
  7365. Console.WriteLine("Object on which call is made is different from the result.");
  7366. return 1;
  7367. }
  7368. }
  7369. if (!(result.ToString() == str))
  7370. {
  7371. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7372. return 1;
  7373. }
  7374. if (result.Arguments.Count != arguments.Length) return 1;
  7375. for (int i = 0; i < arguments.Length; i++)
  7376. {
  7377. if (result.Arguments[i] != arguments[i]) return 1;
  7378. }
  7379. return 0;
  7380. }
  7381. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  7382. {
  7383. if (!(result.NodeType == et))
  7384. {
  7385. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7386. return 1;
  7387. }
  7388. if (!(result.Type == type))
  7389. {
  7390. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7391. return 1;
  7392. }
  7393. if (expr == null)
  7394. {
  7395. Console.WriteLine("expr was null.");
  7396. if (result.Expression != null) return 1;
  7397. }
  7398. else
  7399. {
  7400. if (!(result.Expression.Equals(expr)))
  7401. {
  7402. return 1;
  7403. }
  7404. }
  7405. if (!(result.TypeOperand == typeop)) return 1;
  7406. if (!(result.ToString() == str))
  7407. {
  7408. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7409. return 1;
  7410. }
  7411. return 0;
  7412. }
  7413. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  7414. {
  7415. if (!(result.NodeType == et))
  7416. {
  7417. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7418. return 1;
  7419. }
  7420. if (!(result.Type == type))
  7421. {
  7422. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7423. return 1;
  7424. }
  7425. if (test == null)
  7426. {
  7427. if (result.Test != null) return 1;
  7428. }
  7429. else
  7430. {
  7431. if (!(result.Test.Equals(test))) return 1;
  7432. }
  7433. if (ifTrue == null)
  7434. {
  7435. if (result.IfTrue != null) return 1;
  7436. }
  7437. else
  7438. {
  7439. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  7440. }
  7441. if (ifFalse == null)
  7442. {
  7443. if (result.IfFalse != null) return 1;
  7444. }
  7445. else
  7446. {
  7447. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  7448. }
  7449. if (!(result.ToString() == str)) return 1;
  7450. return 0;
  7451. }
  7452. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  7453. {
  7454. if (!(result.NodeType == et))
  7455. {
  7456. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7457. return 1;
  7458. }
  7459. if (!(result.Type == type))
  7460. {
  7461. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7462. return 1;
  7463. }
  7464. if (exp_expr == null)
  7465. {
  7466. if (result.Expression != null)
  7467. {
  7468. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  7469. return 1;
  7470. }
  7471. }
  7472. else
  7473. {
  7474. if (!(result.Expression.Equals(exp_expr)))
  7475. {
  7476. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  7477. return 1;
  7478. }
  7479. }
  7480. if (!(result.Member == exp_member))
  7481. {
  7482. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  7483. return 1;
  7484. }
  7485. if (!(result.ToString() == str))
  7486. {
  7487. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7488. return 1;
  7489. }
  7490. return 0;
  7491. }
  7492. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  7493. {
  7494. if (!(result.NodeType == et))
  7495. {
  7496. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7497. return 1;
  7498. }
  7499. if (!(result.Type == type))
  7500. {
  7501. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7502. return 1;
  7503. }
  7504. if (!(result.Constructor == constructor))
  7505. {
  7506. Console.WriteLine("Unexpected constructor");
  7507. return 1;
  7508. }
  7509. if (!(result.ToString() == str))
  7510. {
  7511. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7512. return 1;
  7513. }
  7514. if (arguments == null)
  7515. {
  7516. if (result.Arguments.Count != 0)
  7517. {
  7518. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  7519. return 1;
  7520. }
  7521. }
  7522. else
  7523. {
  7524. if (result.Arguments.Count != arguments.Length)
  7525. {
  7526. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  7527. return 1;
  7528. }
  7529. for (int i = 0; i < arguments.Length; i++)
  7530. {
  7531. if (result.Arguments[i] != arguments[i])
  7532. {
  7533. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  7534. return 1;
  7535. }
  7536. }
  7537. }
  7538. if (result.Members == null)
  7539. {
  7540. Console.WriteLine("result.Members was null");
  7541. return 1;
  7542. }
  7543. if (members == null)
  7544. {
  7545. if (result.Members.Count != 0)
  7546. {
  7547. Console.WriteLine("Got more than zero members");
  7548. return 1;
  7549. }
  7550. }
  7551. else
  7552. {
  7553. if (result.Members.Count != members.Length)
  7554. {
  7555. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  7556. return 1;
  7557. }
  7558. for (int i = 0; i < members.Length; i++)
  7559. {
  7560. if (result.Members[i] != members[i])
  7561. {
  7562. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  7563. return 1;
  7564. }
  7565. }
  7566. }
  7567. return 0;
  7568. }
  7569. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  7570. {
  7571. if (!(result.NodeType == et))
  7572. {
  7573. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7574. return 1;
  7575. }
  7576. if (!(result.Type == type))
  7577. {
  7578. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7579. return 1;
  7580. }
  7581. if (!(result.Constructor == constructor))
  7582. {
  7583. Console.WriteLine("Constructor is different from expected.");
  7584. return 1;
  7585. }
  7586. if (!(result.ToString() == str))
  7587. {
  7588. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7589. return 1;
  7590. }
  7591. if (result.Arguments.Count != arguments.Length)
  7592. {
  7593. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  7594. return 1;
  7595. }
  7596. for (int i = 0; i < arguments.Length; i++)
  7597. {
  7598. if (result.Arguments[i] != arguments[i])
  7599. {
  7600. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  7601. return 1;
  7602. }
  7603. }
  7604. if (result.Members != null)
  7605. {
  7606. Console.WriteLine("result.Members isn't null");
  7607. return 1;
  7608. }
  7609. return 0;
  7610. }
  7611. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  7612. {
  7613. if (!(result.NodeType == et))
  7614. {
  7615. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7616. return 1;
  7617. }
  7618. if (!(result.Type == type))
  7619. {
  7620. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7621. return 1;
  7622. }
  7623. if (!(result.NewExpression == newExpression)) return 1;
  7624. if (!(result.ToString() == str))
  7625. {
  7626. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7627. return 1;
  7628. }
  7629. if (result.Initializers.Count != initializers.Length) return 1;
  7630. for (int i = 0; i < initializers.Length; i++)
  7631. {
  7632. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  7633. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  7634. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  7635. {
  7636. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  7637. }
  7638. }
  7639. return 0;
  7640. }
  7641. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  7642. {
  7643. if (result.AddMethod != exp_mi) return 1;
  7644. if (!(result.ToString() == str))
  7645. {
  7646. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7647. return 1;
  7648. }
  7649. if (result.Arguments.Count != args.Length) return 1;
  7650. for (int i = 0; i < args.Length; i++)
  7651. {
  7652. if (result.Arguments[i] != args[i]) return 1;
  7653. }
  7654. return 0;
  7655. }
  7656. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  7657. {
  7658. if (!(result.BindingType == bt)) return 1;
  7659. if (!(result.Expression == expr)) return 1;
  7660. if (!(result.Member.Equals(member))) return 1;
  7661. if (!(result.ToString() == str))
  7662. {
  7663. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7664. return 1;
  7665. }
  7666. return 0;
  7667. }
  7668. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  7669. {
  7670. if (!(result.BindingType == bt)) return 1;
  7671. if (!(result.Member.Equals(member))) return 1;
  7672. if (!(result.ToString() == str))
  7673. {
  7674. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7675. return 1;
  7676. }
  7677. if (result.Initializers.Count != initializers.Length) return 1;
  7678. for (int i = 0; i < initializers.Length; i++)
  7679. {
  7680. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  7681. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  7682. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  7683. {
  7684. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  7685. }
  7686. }
  7687. return 0;
  7688. }
  7689. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  7690. {
  7691. if (!(result.BindingType == bt)) return 1;
  7692. if (!(result.Member.Equals(member))) return 1;
  7693. if (!(result.ToString() == str))
  7694. {
  7695. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7696. return 1;
  7697. }
  7698. if (result.Bindings.Count != bindings.Length) return 1;
  7699. for (int i = 0; i < bindings.Length; i++)
  7700. {
  7701. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  7702. }
  7703. return 0;
  7704. }
  7705. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  7706. {
  7707. if (!(result.NodeType == et))
  7708. {
  7709. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7710. return 1;
  7711. }
  7712. if (!(result.Type == type))
  7713. {
  7714. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7715. return 1;
  7716. }
  7717. if (!(result.NewExpression.Equals(newExpr))) return 1;
  7718. if (!(result.ToString() == str)) return 1;
  7719. if (result.Bindings.Count != bindings.Length) return 1;
  7720. for (int i = 0; i < bindings.Length; i++)
  7721. {
  7722. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  7723. }
  7724. return 0;
  7725. }
  7726. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  7727. {
  7728. if (!(result.NodeType == et))
  7729. {
  7730. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7731. return 1;
  7732. }
  7733. if (!(result.Type == type))
  7734. {
  7735. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7736. return 1;
  7737. }
  7738. if (result.Expressions.Count != expr.Length) return 1;
  7739. for (int i = 0; i < expr.Length; i++)
  7740. {
  7741. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  7742. }
  7743. if (!(result.ToString() == str))
  7744. {
  7745. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7746. return 1;
  7747. }
  7748. return 0;
  7749. }
  7750. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  7751. {
  7752. if (!(result.NodeType == et))
  7753. {
  7754. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7755. return 1;
  7756. }
  7757. if (!(result.Type == type))
  7758. {
  7759. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7760. return 1;
  7761. }
  7762. if (!(result.Name == name)) return 1;
  7763. if (!(result.ToString() == str))
  7764. {
  7765. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7766. return 1;
  7767. }
  7768. return 0;
  7769. }
  7770. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  7771. {
  7772. if (!(result.NodeType == et))
  7773. {
  7774. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7775. return 1;
  7776. }
  7777. if (!(result.Type == type))
  7778. {
  7779. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7780. return 1;
  7781. }
  7782. if (expr == null)
  7783. {
  7784. if (result.Body != null) return 1;
  7785. }
  7786. else
  7787. {
  7788. if (!(result.Body.Equals(expr))) return 1;
  7789. }
  7790. if (result.Parameters.Count != parms.Length) return 1;
  7791. for (int i = 0; i < parms.Length; i++)
  7792. {
  7793. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  7794. }
  7795. if (!(result.ToString() == str))
  7796. {
  7797. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  7798. return 1;
  7799. }
  7800. return 0;
  7801. }
  7802. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  7803. {
  7804. if (!(result.NodeType == et))
  7805. {
  7806. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7807. return 1;
  7808. }
  7809. if (!(result.Type == type))
  7810. {
  7811. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7812. return 1;
  7813. }
  7814. if (expr == null)
  7815. {
  7816. if (result.Expression != null) return 1;
  7817. }
  7818. else
  7819. {
  7820. if (!(result.Expression.Equals(expr))) return 1;
  7821. }
  7822. if (result.Arguments.Count != args.Length) return 1;
  7823. for (int i = 0; i < args.Length; i++)
  7824. {
  7825. if (!(result.Arguments[i].Equals(args[i])))
  7826. {
  7827. return 1;
  7828. }
  7829. }
  7830. if (result.ToString() != str)
  7831. {
  7832. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7833. return 1;
  7834. }
  7835. return 0;
  7836. }
  7837. }
  7838. namespace Not
  7839. {
  7840. // Declaring user-defined types for testing
  7841. struct TC1
  7842. {
  7843. public static TC1 operator !(TC1 c)
  7844. {
  7845. return new TC1();
  7846. }
  7847. public static TC1 operator ~(TC1 c)
  7848. {
  7849. return new TC1();
  7850. }
  7851. }
  7852. struct TC2
  7853. {
  7854. public static TC2 operator ~(TC2 c)
  7855. {
  7856. return new TC2();
  7857. }
  7858. }
  7859. struct TC3
  7860. {
  7861. public static TC3 Meth1(TC3 c)
  7862. {
  7863. return new TC3();
  7864. }
  7865. }
  7866. }
  7867. }
  7868. //-------- Scenario 793
  7869. namespace Scenario793
  7870. {
  7871. namespace Not
  7872. {
  7873. public class Test
  7874. {
  7875. // Overload-2: Test for functionality: Passing null methodinfo
  7876. public static int Test12()
  7877. {
  7878. TC2? ctest = new TC2?();
  7879. ConstantExpression ce = Expression.Constant(ctest, typeof(TC2?));
  7880. Type exp_type = typeof(TC2?);
  7881. ExpressionType exp_et = ExpressionType.Not;
  7882. string exp_str = "Not(" + ce.ToString() + ")";
  7883. Expression exp_operand = ce;
  7884. MethodInfo exp_mi = typeof(TC2).GetMethod("op_OnesComplement");
  7885. UnaryExpression result = Expression.Not(ce, null);
  7886. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, true, true);
  7887. }
  7888. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not12__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  7889. public static Expression Not12__()
  7890. {
  7891. if (Main() != 0)
  7892. {
  7893. throw new Exception();
  7894. }
  7895. else
  7896. {
  7897. return Expression.Constant(0);
  7898. }
  7899. }
  7900. public static int Main()
  7901. {
  7902. return Test12();
  7903. }
  7904. }
  7905. }
  7906. public static class Extension
  7907. {
  7908. public static bool CompareParamName(this ArgumentException ex, string expected)
  7909. {
  7910. #if SILVERLIGHT
  7911. #if SLRESOURCES
  7912. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  7913. #else
  7914. return true;
  7915. #endif
  7916. #else
  7917. return ex.ParamName == expected;
  7918. #endif
  7919. }
  7920. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  7921. {
  7922. #if SILVERLIGHT
  7923. #if SLRESOURCES
  7924. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  7925. #else
  7926. return true;
  7927. #endif
  7928. #else
  7929. return ex.ParamName == expected;
  7930. #endif
  7931. }
  7932. }
  7933. public static class Verification
  7934. {
  7935. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  7936. {
  7937. if (!(result.NodeType == et))
  7938. {
  7939. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7940. return 1;
  7941. }
  7942. if (!(result.Type == type))
  7943. {
  7944. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7945. return 1;
  7946. }
  7947. if (val == null)
  7948. {
  7949. if (result.Value != null) return 1;
  7950. }
  7951. else
  7952. {
  7953. if (!(result.Value.Equals(val))) return 1;
  7954. }
  7955. if (!(result.ToString() == str)) return 1;
  7956. return 0;
  7957. }
  7958. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  7959. {
  7960. if (!(result.NodeType == et))
  7961. {
  7962. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7963. return 1;
  7964. }
  7965. if (!(result.Type == type))
  7966. {
  7967. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7968. return 1;
  7969. }
  7970. if (operand == null)
  7971. {
  7972. if (result.Operand != null) return 1;
  7973. }
  7974. else
  7975. {
  7976. if (!(result.Operand.Equals(operand))) return 1;
  7977. }
  7978. if (!(result.ToString() == str))
  7979. {
  7980. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  7981. return 1;
  7982. }
  7983. if (result.Method != mi) return 1;
  7984. if (result.IsLifted != islifted) return 1;
  7985. if (result.IsLiftedToNull != isliftedtonull) return 1;
  7986. return 0;
  7987. }
  7988. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  7989. {
  7990. if (!(result.NodeType == et))
  7991. {
  7992. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  7993. return 1;
  7994. }
  7995. if (!(result.Type == type))
  7996. {
  7997. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  7998. return 1;
  7999. }
  8000. if (left == null)
  8001. {
  8002. if (result.Left != null)
  8003. {
  8004. Console.WriteLine("left was null");
  8005. return 1;
  8006. }
  8007. }
  8008. else
  8009. {
  8010. if (!(result.Left.Equals(left)))
  8011. {
  8012. Console.WriteLine("left was different");
  8013. return 1;
  8014. }
  8015. }
  8016. if (right == null)
  8017. {
  8018. if (result.Right != null) return 1;
  8019. }
  8020. else
  8021. {
  8022. if (!(result.Right.Equals(right))) return 1;
  8023. }
  8024. if (!(result.ToString() == str))
  8025. {
  8026. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8027. return 1;
  8028. }
  8029. if (result.Method != mi) return 1;
  8030. if (result.IsLifted != islifted) return 1;
  8031. if (result.IsLiftedToNull != isliftedtonull) return 1;
  8032. if (result.Conversion != null) return 1;
  8033. return 0;
  8034. }
  8035. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  8036. {
  8037. if (!(result.NodeType == et))
  8038. {
  8039. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8040. return 1;
  8041. }
  8042. if (!(result.Type == type))
  8043. {
  8044. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8045. return 1;
  8046. }
  8047. if (left == null)
  8048. {
  8049. if (result.Left != null) return 1;
  8050. }
  8051. else
  8052. {
  8053. if (!(result.Left.Equals(left))) return 1;
  8054. }
  8055. if (right == null)
  8056. {
  8057. if (result.Right != null) return 1;
  8058. }
  8059. else
  8060. {
  8061. if (!(result.Right.Equals(right))) return 1;
  8062. }
  8063. if (!(result.ToString() == str)) return 1;
  8064. if (result.Method != mi) return 1;
  8065. if (result.IsLifted != islifted) return 1;
  8066. if (result.IsLiftedToNull != isliftedtonull) return 1;
  8067. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  8068. return 0;
  8069. }
  8070. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  8071. {
  8072. if (!(result.NodeType == et))
  8073. {
  8074. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8075. return 1;
  8076. }
  8077. if (!(result.Type == type))
  8078. {
  8079. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8080. return 1;
  8081. }
  8082. if (!(result.Method == method)) return 1;
  8083. if (obj == null)
  8084. {
  8085. if (result.Object != null)
  8086. {
  8087. Console.WriteLine("Expected object to be null.");
  8088. return 1;
  8089. }
  8090. }
  8091. else
  8092. {
  8093. if (!(result.Object.Equals(obj)))
  8094. {
  8095. Console.WriteLine("Object on which call is made is different from the result.");
  8096. return 1;
  8097. }
  8098. }
  8099. if (!(result.ToString() == str))
  8100. {
  8101. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8102. return 1;
  8103. }
  8104. if (result.Arguments.Count != arguments.Length) return 1;
  8105. for (int i = 0; i < arguments.Length; i++)
  8106. {
  8107. if (result.Arguments[i] != arguments[i]) return 1;
  8108. }
  8109. return 0;
  8110. }
  8111. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  8112. {
  8113. if (!(result.NodeType == et))
  8114. {
  8115. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8116. return 1;
  8117. }
  8118. if (!(result.Type == type))
  8119. {
  8120. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8121. return 1;
  8122. }
  8123. if (expr == null)
  8124. {
  8125. Console.WriteLine("expr was null.");
  8126. if (result.Expression != null) return 1;
  8127. }
  8128. else
  8129. {
  8130. if (!(result.Expression.Equals(expr)))
  8131. {
  8132. return 1;
  8133. }
  8134. }
  8135. if (!(result.TypeOperand == typeop)) return 1;
  8136. if (!(result.ToString() == str))
  8137. {
  8138. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8139. return 1;
  8140. }
  8141. return 0;
  8142. }
  8143. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  8144. {
  8145. if (!(result.NodeType == et))
  8146. {
  8147. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8148. return 1;
  8149. }
  8150. if (!(result.Type == type))
  8151. {
  8152. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8153. return 1;
  8154. }
  8155. if (test == null)
  8156. {
  8157. if (result.Test != null) return 1;
  8158. }
  8159. else
  8160. {
  8161. if (!(result.Test.Equals(test))) return 1;
  8162. }
  8163. if (ifTrue == null)
  8164. {
  8165. if (result.IfTrue != null) return 1;
  8166. }
  8167. else
  8168. {
  8169. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  8170. }
  8171. if (ifFalse == null)
  8172. {
  8173. if (result.IfFalse != null) return 1;
  8174. }
  8175. else
  8176. {
  8177. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  8178. }
  8179. if (!(result.ToString() == str)) return 1;
  8180. return 0;
  8181. }
  8182. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  8183. {
  8184. if (!(result.NodeType == et))
  8185. {
  8186. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8187. return 1;
  8188. }
  8189. if (!(result.Type == type))
  8190. {
  8191. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8192. return 1;
  8193. }
  8194. if (exp_expr == null)
  8195. {
  8196. if (result.Expression != null)
  8197. {
  8198. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  8199. return 1;
  8200. }
  8201. }
  8202. else
  8203. {
  8204. if (!(result.Expression.Equals(exp_expr)))
  8205. {
  8206. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  8207. return 1;
  8208. }
  8209. }
  8210. if (!(result.Member == exp_member))
  8211. {
  8212. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  8213. return 1;
  8214. }
  8215. if (!(result.ToString() == str))
  8216. {
  8217. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8218. return 1;
  8219. }
  8220. return 0;
  8221. }
  8222. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  8223. {
  8224. if (!(result.NodeType == et))
  8225. {
  8226. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8227. return 1;
  8228. }
  8229. if (!(result.Type == type))
  8230. {
  8231. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8232. return 1;
  8233. }
  8234. if (!(result.Constructor == constructor))
  8235. {
  8236. Console.WriteLine("Unexpected constructor");
  8237. return 1;
  8238. }
  8239. if (!(result.ToString() == str))
  8240. {
  8241. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8242. return 1;
  8243. }
  8244. if (arguments == null)
  8245. {
  8246. if (result.Arguments.Count != 0)
  8247. {
  8248. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  8249. return 1;
  8250. }
  8251. }
  8252. else
  8253. {
  8254. if (result.Arguments.Count != arguments.Length)
  8255. {
  8256. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  8257. return 1;
  8258. }
  8259. for (int i = 0; i < arguments.Length; i++)
  8260. {
  8261. if (result.Arguments[i] != arguments[i])
  8262. {
  8263. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  8264. return 1;
  8265. }
  8266. }
  8267. }
  8268. if (result.Members == null)
  8269. {
  8270. Console.WriteLine("result.Members was null");
  8271. return 1;
  8272. }
  8273. if (members == null)
  8274. {
  8275. if (result.Members.Count != 0)
  8276. {
  8277. Console.WriteLine("Got more than zero members");
  8278. return 1;
  8279. }
  8280. }
  8281. else
  8282. {
  8283. if (result.Members.Count != members.Length)
  8284. {
  8285. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  8286. return 1;
  8287. }
  8288. for (int i = 0; i < members.Length; i++)
  8289. {
  8290. if (result.Members[i] != members[i])
  8291. {
  8292. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  8293. return 1;
  8294. }
  8295. }
  8296. }
  8297. return 0;
  8298. }
  8299. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  8300. {
  8301. if (!(result.NodeType == et))
  8302. {
  8303. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8304. return 1;
  8305. }
  8306. if (!(result.Type == type))
  8307. {
  8308. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8309. return 1;
  8310. }
  8311. if (!(result.Constructor == constructor))
  8312. {
  8313. Console.WriteLine("Constructor is different from expected.");
  8314. return 1;
  8315. }
  8316. if (!(result.ToString() == str))
  8317. {
  8318. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8319. return 1;
  8320. }
  8321. if (result.Arguments.Count != arguments.Length)
  8322. {
  8323. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  8324. return 1;
  8325. }
  8326. for (int i = 0; i < arguments.Length; i++)
  8327. {
  8328. if (result.Arguments[i] != arguments[i])
  8329. {
  8330. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  8331. return 1;
  8332. }
  8333. }
  8334. if (result.Members != null)
  8335. {
  8336. Console.WriteLine("result.Members isn't null");
  8337. return 1;
  8338. }
  8339. return 0;
  8340. }
  8341. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  8342. {
  8343. if (!(result.NodeType == et))
  8344. {
  8345. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8346. return 1;
  8347. }
  8348. if (!(result.Type == type))
  8349. {
  8350. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8351. return 1;
  8352. }
  8353. if (!(result.NewExpression == newExpression)) return 1;
  8354. if (!(result.ToString() == str))
  8355. {
  8356. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8357. return 1;
  8358. }
  8359. if (result.Initializers.Count != initializers.Length) return 1;
  8360. for (int i = 0; i < initializers.Length; i++)
  8361. {
  8362. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  8363. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  8364. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  8365. {
  8366. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  8367. }
  8368. }
  8369. return 0;
  8370. }
  8371. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  8372. {
  8373. if (result.AddMethod != exp_mi) return 1;
  8374. if (!(result.ToString() == str))
  8375. {
  8376. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8377. return 1;
  8378. }
  8379. if (result.Arguments.Count != args.Length) return 1;
  8380. for (int i = 0; i < args.Length; i++)
  8381. {
  8382. if (result.Arguments[i] != args[i]) return 1;
  8383. }
  8384. return 0;
  8385. }
  8386. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  8387. {
  8388. if (!(result.BindingType == bt)) return 1;
  8389. if (!(result.Expression == expr)) return 1;
  8390. if (!(result.Member.Equals(member))) return 1;
  8391. if (!(result.ToString() == str))
  8392. {
  8393. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8394. return 1;
  8395. }
  8396. return 0;
  8397. }
  8398. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  8399. {
  8400. if (!(result.BindingType == bt)) return 1;
  8401. if (!(result.Member.Equals(member))) return 1;
  8402. if (!(result.ToString() == str))
  8403. {
  8404. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8405. return 1;
  8406. }
  8407. if (result.Initializers.Count != initializers.Length) return 1;
  8408. for (int i = 0; i < initializers.Length; i++)
  8409. {
  8410. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  8411. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  8412. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  8413. {
  8414. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  8415. }
  8416. }
  8417. return 0;
  8418. }
  8419. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  8420. {
  8421. if (!(result.BindingType == bt)) return 1;
  8422. if (!(result.Member.Equals(member))) return 1;
  8423. if (!(result.ToString() == str))
  8424. {
  8425. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8426. return 1;
  8427. }
  8428. if (result.Bindings.Count != bindings.Length) return 1;
  8429. for (int i = 0; i < bindings.Length; i++)
  8430. {
  8431. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  8432. }
  8433. return 0;
  8434. }
  8435. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  8436. {
  8437. if (!(result.NodeType == et))
  8438. {
  8439. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8440. return 1;
  8441. }
  8442. if (!(result.Type == type))
  8443. {
  8444. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8445. return 1;
  8446. }
  8447. if (!(result.NewExpression.Equals(newExpr))) return 1;
  8448. if (!(result.ToString() == str)) return 1;
  8449. if (result.Bindings.Count != bindings.Length) return 1;
  8450. for (int i = 0; i < bindings.Length; i++)
  8451. {
  8452. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  8453. }
  8454. return 0;
  8455. }
  8456. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  8457. {
  8458. if (!(result.NodeType == et))
  8459. {
  8460. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8461. return 1;
  8462. }
  8463. if (!(result.Type == type))
  8464. {
  8465. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8466. return 1;
  8467. }
  8468. if (result.Expressions.Count != expr.Length) return 1;
  8469. for (int i = 0; i < expr.Length; i++)
  8470. {
  8471. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  8472. }
  8473. if (!(result.ToString() == str))
  8474. {
  8475. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8476. return 1;
  8477. }
  8478. return 0;
  8479. }
  8480. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  8481. {
  8482. if (!(result.NodeType == et))
  8483. {
  8484. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8485. return 1;
  8486. }
  8487. if (!(result.Type == type))
  8488. {
  8489. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8490. return 1;
  8491. }
  8492. if (!(result.Name == name)) return 1;
  8493. if (!(result.ToString() == str))
  8494. {
  8495. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8496. return 1;
  8497. }
  8498. return 0;
  8499. }
  8500. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  8501. {
  8502. if (!(result.NodeType == et))
  8503. {
  8504. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8505. return 1;
  8506. }
  8507. if (!(result.Type == type))
  8508. {
  8509. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8510. return 1;
  8511. }
  8512. if (expr == null)
  8513. {
  8514. if (result.Body != null) return 1;
  8515. }
  8516. else
  8517. {
  8518. if (!(result.Body.Equals(expr))) return 1;
  8519. }
  8520. if (result.Parameters.Count != parms.Length) return 1;
  8521. for (int i = 0; i < parms.Length; i++)
  8522. {
  8523. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  8524. }
  8525. if (!(result.ToString() == str))
  8526. {
  8527. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8528. return 1;
  8529. }
  8530. return 0;
  8531. }
  8532. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  8533. {
  8534. if (!(result.NodeType == et))
  8535. {
  8536. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8537. return 1;
  8538. }
  8539. if (!(result.Type == type))
  8540. {
  8541. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8542. return 1;
  8543. }
  8544. if (expr == null)
  8545. {
  8546. if (result.Expression != null) return 1;
  8547. }
  8548. else
  8549. {
  8550. if (!(result.Expression.Equals(expr))) return 1;
  8551. }
  8552. if (result.Arguments.Count != args.Length) return 1;
  8553. for (int i = 0; i < args.Length; i++)
  8554. {
  8555. if (!(result.Arguments[i].Equals(args[i])))
  8556. {
  8557. return 1;
  8558. }
  8559. }
  8560. if (result.ToString() != str)
  8561. {
  8562. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8563. return 1;
  8564. }
  8565. return 0;
  8566. }
  8567. }
  8568. namespace Not
  8569. {
  8570. // Declaring user-defined types for testing
  8571. struct TC1
  8572. {
  8573. public static TC1 operator !(TC1 c)
  8574. {
  8575. return new TC1();
  8576. }
  8577. public static TC1 operator ~(TC1 c)
  8578. {
  8579. return new TC1();
  8580. }
  8581. }
  8582. struct TC2
  8583. {
  8584. public static TC2 operator ~(TC2 c)
  8585. {
  8586. return new TC2();
  8587. }
  8588. }
  8589. struct TC3
  8590. {
  8591. public static TC3 Meth1(TC3 c)
  8592. {
  8593. return new TC3();
  8594. }
  8595. }
  8596. }
  8597. }
  8598. //-------- Scenario 794
  8599. namespace Scenario794
  8600. {
  8601. namespace Not
  8602. {
  8603. public class Test
  8604. {
  8605. // Overload-2: Passing null methodinfo
  8606. public static int Test13a()
  8607. {
  8608. TC3 ctest = new TC3();
  8609. ConstantExpression ce = Expression.Constant(ctest, typeof(TC3));
  8610. try
  8611. {
  8612. UnaryExpression result = Expression.Not(ce, null);
  8613. return 1;
  8614. }
  8615. catch (InvalidOperationException)
  8616. {
  8617. return 0;
  8618. }
  8619. }
  8620. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not13a__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  8621. public static Expression Not13a__()
  8622. {
  8623. if (Main() != 0)
  8624. {
  8625. throw new Exception();
  8626. }
  8627. else
  8628. {
  8629. return Expression.Constant(0);
  8630. }
  8631. }
  8632. public static int Main()
  8633. {
  8634. return Test13a();
  8635. }
  8636. }
  8637. }
  8638. public static class Extension
  8639. {
  8640. public static bool CompareParamName(this ArgumentException ex, string expected)
  8641. {
  8642. #if SILVERLIGHT
  8643. #if SLRESOURCES
  8644. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  8645. #else
  8646. return true;
  8647. #endif
  8648. #else
  8649. return ex.ParamName == expected;
  8650. #endif
  8651. }
  8652. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  8653. {
  8654. #if SILVERLIGHT
  8655. #if SLRESOURCES
  8656. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  8657. #else
  8658. return true;
  8659. #endif
  8660. #else
  8661. return ex.ParamName == expected;
  8662. #endif
  8663. }
  8664. }
  8665. public static class Verification
  8666. {
  8667. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  8668. {
  8669. if (!(result.NodeType == et))
  8670. {
  8671. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8672. return 1;
  8673. }
  8674. if (!(result.Type == type))
  8675. {
  8676. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8677. return 1;
  8678. }
  8679. if (val == null)
  8680. {
  8681. if (result.Value != null) return 1;
  8682. }
  8683. else
  8684. {
  8685. if (!(result.Value.Equals(val))) return 1;
  8686. }
  8687. if (!(result.ToString() == str)) return 1;
  8688. return 0;
  8689. }
  8690. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  8691. {
  8692. if (!(result.NodeType == et))
  8693. {
  8694. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8695. return 1;
  8696. }
  8697. if (!(result.Type == type))
  8698. {
  8699. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8700. return 1;
  8701. }
  8702. if (operand == null)
  8703. {
  8704. if (result.Operand != null) return 1;
  8705. }
  8706. else
  8707. {
  8708. if (!(result.Operand.Equals(operand))) return 1;
  8709. }
  8710. if (!(result.ToString() == str))
  8711. {
  8712. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8713. return 1;
  8714. }
  8715. if (result.Method != mi) return 1;
  8716. if (result.IsLifted != islifted) return 1;
  8717. if (result.IsLiftedToNull != isliftedtonull) return 1;
  8718. return 0;
  8719. }
  8720. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  8721. {
  8722. if (!(result.NodeType == et))
  8723. {
  8724. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8725. return 1;
  8726. }
  8727. if (!(result.Type == type))
  8728. {
  8729. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8730. return 1;
  8731. }
  8732. if (left == null)
  8733. {
  8734. if (result.Left != null)
  8735. {
  8736. Console.WriteLine("left was null");
  8737. return 1;
  8738. }
  8739. }
  8740. else
  8741. {
  8742. if (!(result.Left.Equals(left)))
  8743. {
  8744. Console.WriteLine("left was different");
  8745. return 1;
  8746. }
  8747. }
  8748. if (right == null)
  8749. {
  8750. if (result.Right != null) return 1;
  8751. }
  8752. else
  8753. {
  8754. if (!(result.Right.Equals(right))) return 1;
  8755. }
  8756. if (!(result.ToString() == str))
  8757. {
  8758. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8759. return 1;
  8760. }
  8761. if (result.Method != mi) return 1;
  8762. if (result.IsLifted != islifted) return 1;
  8763. if (result.IsLiftedToNull != isliftedtonull) return 1;
  8764. if (result.Conversion != null) return 1;
  8765. return 0;
  8766. }
  8767. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  8768. {
  8769. if (!(result.NodeType == et))
  8770. {
  8771. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8772. return 1;
  8773. }
  8774. if (!(result.Type == type))
  8775. {
  8776. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8777. return 1;
  8778. }
  8779. if (left == null)
  8780. {
  8781. if (result.Left != null) return 1;
  8782. }
  8783. else
  8784. {
  8785. if (!(result.Left.Equals(left))) return 1;
  8786. }
  8787. if (right == null)
  8788. {
  8789. if (result.Right != null) return 1;
  8790. }
  8791. else
  8792. {
  8793. if (!(result.Right.Equals(right))) return 1;
  8794. }
  8795. if (!(result.ToString() == str)) return 1;
  8796. if (result.Method != mi) return 1;
  8797. if (result.IsLifted != islifted) return 1;
  8798. if (result.IsLiftedToNull != isliftedtonull) return 1;
  8799. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  8800. return 0;
  8801. }
  8802. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  8803. {
  8804. if (!(result.NodeType == et))
  8805. {
  8806. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8807. return 1;
  8808. }
  8809. if (!(result.Type == type))
  8810. {
  8811. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8812. return 1;
  8813. }
  8814. if (!(result.Method == method)) return 1;
  8815. if (obj == null)
  8816. {
  8817. if (result.Object != null)
  8818. {
  8819. Console.WriteLine("Expected object to be null.");
  8820. return 1;
  8821. }
  8822. }
  8823. else
  8824. {
  8825. if (!(result.Object.Equals(obj)))
  8826. {
  8827. Console.WriteLine("Object on which call is made is different from the result.");
  8828. return 1;
  8829. }
  8830. }
  8831. if (!(result.ToString() == str))
  8832. {
  8833. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8834. return 1;
  8835. }
  8836. if (result.Arguments.Count != arguments.Length) return 1;
  8837. for (int i = 0; i < arguments.Length; i++)
  8838. {
  8839. if (result.Arguments[i] != arguments[i]) return 1;
  8840. }
  8841. return 0;
  8842. }
  8843. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  8844. {
  8845. if (!(result.NodeType == et))
  8846. {
  8847. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8848. return 1;
  8849. }
  8850. if (!(result.Type == type))
  8851. {
  8852. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8853. return 1;
  8854. }
  8855. if (expr == null)
  8856. {
  8857. Console.WriteLine("expr was null.");
  8858. if (result.Expression != null) return 1;
  8859. }
  8860. else
  8861. {
  8862. if (!(result.Expression.Equals(expr)))
  8863. {
  8864. return 1;
  8865. }
  8866. }
  8867. if (!(result.TypeOperand == typeop)) return 1;
  8868. if (!(result.ToString() == str))
  8869. {
  8870. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  8871. return 1;
  8872. }
  8873. return 0;
  8874. }
  8875. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  8876. {
  8877. if (!(result.NodeType == et))
  8878. {
  8879. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8880. return 1;
  8881. }
  8882. if (!(result.Type == type))
  8883. {
  8884. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8885. return 1;
  8886. }
  8887. if (test == null)
  8888. {
  8889. if (result.Test != null) return 1;
  8890. }
  8891. else
  8892. {
  8893. if (!(result.Test.Equals(test))) return 1;
  8894. }
  8895. if (ifTrue == null)
  8896. {
  8897. if (result.IfTrue != null) return 1;
  8898. }
  8899. else
  8900. {
  8901. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  8902. }
  8903. if (ifFalse == null)
  8904. {
  8905. if (result.IfFalse != null) return 1;
  8906. }
  8907. else
  8908. {
  8909. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  8910. }
  8911. if (!(result.ToString() == str)) return 1;
  8912. return 0;
  8913. }
  8914. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  8915. {
  8916. if (!(result.NodeType == et))
  8917. {
  8918. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8919. return 1;
  8920. }
  8921. if (!(result.Type == type))
  8922. {
  8923. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8924. return 1;
  8925. }
  8926. if (exp_expr == null)
  8927. {
  8928. if (result.Expression != null)
  8929. {
  8930. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  8931. return 1;
  8932. }
  8933. }
  8934. else
  8935. {
  8936. if (!(result.Expression.Equals(exp_expr)))
  8937. {
  8938. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  8939. return 1;
  8940. }
  8941. }
  8942. if (!(result.Member == exp_member))
  8943. {
  8944. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  8945. return 1;
  8946. }
  8947. if (!(result.ToString() == str))
  8948. {
  8949. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8950. return 1;
  8951. }
  8952. return 0;
  8953. }
  8954. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  8955. {
  8956. if (!(result.NodeType == et))
  8957. {
  8958. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  8959. return 1;
  8960. }
  8961. if (!(result.Type == type))
  8962. {
  8963. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  8964. return 1;
  8965. }
  8966. if (!(result.Constructor == constructor))
  8967. {
  8968. Console.WriteLine("Unexpected constructor");
  8969. return 1;
  8970. }
  8971. if (!(result.ToString() == str))
  8972. {
  8973. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  8974. return 1;
  8975. }
  8976. if (arguments == null)
  8977. {
  8978. if (result.Arguments.Count != 0)
  8979. {
  8980. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  8981. return 1;
  8982. }
  8983. }
  8984. else
  8985. {
  8986. if (result.Arguments.Count != arguments.Length)
  8987. {
  8988. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  8989. return 1;
  8990. }
  8991. for (int i = 0; i < arguments.Length; i++)
  8992. {
  8993. if (result.Arguments[i] != arguments[i])
  8994. {
  8995. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  8996. return 1;
  8997. }
  8998. }
  8999. }
  9000. if (result.Members == null)
  9001. {
  9002. Console.WriteLine("result.Members was null");
  9003. return 1;
  9004. }
  9005. if (members == null)
  9006. {
  9007. if (result.Members.Count != 0)
  9008. {
  9009. Console.WriteLine("Got more than zero members");
  9010. return 1;
  9011. }
  9012. }
  9013. else
  9014. {
  9015. if (result.Members.Count != members.Length)
  9016. {
  9017. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  9018. return 1;
  9019. }
  9020. for (int i = 0; i < members.Length; i++)
  9021. {
  9022. if (result.Members[i] != members[i])
  9023. {
  9024. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  9025. return 1;
  9026. }
  9027. }
  9028. }
  9029. return 0;
  9030. }
  9031. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  9032. {
  9033. if (!(result.NodeType == et))
  9034. {
  9035. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9036. return 1;
  9037. }
  9038. if (!(result.Type == type))
  9039. {
  9040. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9041. return 1;
  9042. }
  9043. if (!(result.Constructor == constructor))
  9044. {
  9045. Console.WriteLine("Constructor is different from expected.");
  9046. return 1;
  9047. }
  9048. if (!(result.ToString() == str))
  9049. {
  9050. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9051. return 1;
  9052. }
  9053. if (result.Arguments.Count != arguments.Length)
  9054. {
  9055. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  9056. return 1;
  9057. }
  9058. for (int i = 0; i < arguments.Length; i++)
  9059. {
  9060. if (result.Arguments[i] != arguments[i])
  9061. {
  9062. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  9063. return 1;
  9064. }
  9065. }
  9066. if (result.Members != null)
  9067. {
  9068. Console.WriteLine("result.Members isn't null");
  9069. return 1;
  9070. }
  9071. return 0;
  9072. }
  9073. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  9074. {
  9075. if (!(result.NodeType == et))
  9076. {
  9077. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9078. return 1;
  9079. }
  9080. if (!(result.Type == type))
  9081. {
  9082. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9083. return 1;
  9084. }
  9085. if (!(result.NewExpression == newExpression)) return 1;
  9086. if (!(result.ToString() == str))
  9087. {
  9088. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9089. return 1;
  9090. }
  9091. if (result.Initializers.Count != initializers.Length) return 1;
  9092. for (int i = 0; i < initializers.Length; i++)
  9093. {
  9094. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  9095. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  9096. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  9097. {
  9098. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  9099. }
  9100. }
  9101. return 0;
  9102. }
  9103. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  9104. {
  9105. if (result.AddMethod != exp_mi) return 1;
  9106. if (!(result.ToString() == str))
  9107. {
  9108. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9109. return 1;
  9110. }
  9111. if (result.Arguments.Count != args.Length) return 1;
  9112. for (int i = 0; i < args.Length; i++)
  9113. {
  9114. if (result.Arguments[i] != args[i]) return 1;
  9115. }
  9116. return 0;
  9117. }
  9118. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  9119. {
  9120. if (!(result.BindingType == bt)) return 1;
  9121. if (!(result.Expression == expr)) return 1;
  9122. if (!(result.Member.Equals(member))) return 1;
  9123. if (!(result.ToString() == str))
  9124. {
  9125. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9126. return 1;
  9127. }
  9128. return 0;
  9129. }
  9130. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  9131. {
  9132. if (!(result.BindingType == bt)) return 1;
  9133. if (!(result.Member.Equals(member))) return 1;
  9134. if (!(result.ToString() == str))
  9135. {
  9136. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9137. return 1;
  9138. }
  9139. if (result.Initializers.Count != initializers.Length) return 1;
  9140. for (int i = 0; i < initializers.Length; i++)
  9141. {
  9142. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  9143. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  9144. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  9145. {
  9146. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  9147. }
  9148. }
  9149. return 0;
  9150. }
  9151. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  9152. {
  9153. if (!(result.BindingType == bt)) return 1;
  9154. if (!(result.Member.Equals(member))) return 1;
  9155. if (!(result.ToString() == str))
  9156. {
  9157. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9158. return 1;
  9159. }
  9160. if (result.Bindings.Count != bindings.Length) return 1;
  9161. for (int i = 0; i < bindings.Length; i++)
  9162. {
  9163. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  9164. }
  9165. return 0;
  9166. }
  9167. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  9168. {
  9169. if (!(result.NodeType == et))
  9170. {
  9171. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9172. return 1;
  9173. }
  9174. if (!(result.Type == type))
  9175. {
  9176. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9177. return 1;
  9178. }
  9179. if (!(result.NewExpression.Equals(newExpr))) return 1;
  9180. if (!(result.ToString() == str)) return 1;
  9181. if (result.Bindings.Count != bindings.Length) return 1;
  9182. for (int i = 0; i < bindings.Length; i++)
  9183. {
  9184. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  9185. }
  9186. return 0;
  9187. }
  9188. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  9189. {
  9190. if (!(result.NodeType == et))
  9191. {
  9192. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9193. return 1;
  9194. }
  9195. if (!(result.Type == type))
  9196. {
  9197. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9198. return 1;
  9199. }
  9200. if (result.Expressions.Count != expr.Length) return 1;
  9201. for (int i = 0; i < expr.Length; i++)
  9202. {
  9203. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  9204. }
  9205. if (!(result.ToString() == str))
  9206. {
  9207. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9208. return 1;
  9209. }
  9210. return 0;
  9211. }
  9212. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  9213. {
  9214. if (!(result.NodeType == et))
  9215. {
  9216. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9217. return 1;
  9218. }
  9219. if (!(result.Type == type))
  9220. {
  9221. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9222. return 1;
  9223. }
  9224. if (!(result.Name == name)) return 1;
  9225. if (!(result.ToString() == str))
  9226. {
  9227. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9228. return 1;
  9229. }
  9230. return 0;
  9231. }
  9232. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  9233. {
  9234. if (!(result.NodeType == et))
  9235. {
  9236. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9237. return 1;
  9238. }
  9239. if (!(result.Type == type))
  9240. {
  9241. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9242. return 1;
  9243. }
  9244. if (expr == null)
  9245. {
  9246. if (result.Body != null) return 1;
  9247. }
  9248. else
  9249. {
  9250. if (!(result.Body.Equals(expr))) return 1;
  9251. }
  9252. if (result.Parameters.Count != parms.Length) return 1;
  9253. for (int i = 0; i < parms.Length; i++)
  9254. {
  9255. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  9256. }
  9257. if (!(result.ToString() == str))
  9258. {
  9259. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9260. return 1;
  9261. }
  9262. return 0;
  9263. }
  9264. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  9265. {
  9266. if (!(result.NodeType == et))
  9267. {
  9268. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9269. return 1;
  9270. }
  9271. if (!(result.Type == type))
  9272. {
  9273. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9274. return 1;
  9275. }
  9276. if (expr == null)
  9277. {
  9278. if (result.Expression != null) return 1;
  9279. }
  9280. else
  9281. {
  9282. if (!(result.Expression.Equals(expr))) return 1;
  9283. }
  9284. if (result.Arguments.Count != args.Length) return 1;
  9285. for (int i = 0; i < args.Length; i++)
  9286. {
  9287. if (!(result.Arguments[i].Equals(args[i])))
  9288. {
  9289. return 1;
  9290. }
  9291. }
  9292. if (result.ToString() != str)
  9293. {
  9294. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  9295. return 1;
  9296. }
  9297. return 0;
  9298. }
  9299. }
  9300. namespace Not
  9301. {
  9302. // Declaring user-defined types for testing
  9303. struct TC1
  9304. {
  9305. public static TC1 operator !(TC1 c)
  9306. {
  9307. return new TC1();
  9308. }
  9309. public static TC1 operator ~(TC1 c)
  9310. {
  9311. return new TC1();
  9312. }
  9313. }
  9314. struct TC2
  9315. {
  9316. public static TC2 operator ~(TC2 c)
  9317. {
  9318. return new TC2();
  9319. }
  9320. }
  9321. struct TC3
  9322. {
  9323. public static TC3 Meth1(TC3 c)
  9324. {
  9325. return new TC3();
  9326. }
  9327. }
  9328. }
  9329. }
  9330. //-------- Scenario 795
  9331. namespace Scenario795
  9332. {
  9333. namespace Not
  9334. {
  9335. public class Test
  9336. {
  9337. // Overload-2: Expression is null and MethodInfo is non-null
  9338. public static int Test13b()
  9339. {
  9340. TC3 ctest = new TC3();
  9341. ConstantExpression ce = Expression.Constant(ctest, typeof(TC3));
  9342. MethodInfo exp_mi = typeof(TC3).GetMethod("Meth1");
  9343. try
  9344. {
  9345. ce = null;
  9346. UnaryExpression result = Expression.Not(ce, exp_mi);
  9347. return 1;
  9348. }
  9349. catch (ArgumentNullException ane)
  9350. {
  9351. if (!ane.CompareParamName("expression")) return 1;
  9352. return 0;
  9353. }
  9354. }
  9355. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not13b__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  9356. public static Expression Not13b__()
  9357. {
  9358. if (Main() != 0)
  9359. {
  9360. throw new Exception();
  9361. }
  9362. else
  9363. {
  9364. return Expression.Constant(0);
  9365. }
  9366. }
  9367. public static int Main()
  9368. {
  9369. return Test13b();
  9370. }
  9371. }
  9372. }
  9373. public static class Extension
  9374. {
  9375. public static bool CompareParamName(this ArgumentException ex, string expected)
  9376. {
  9377. #if SILVERLIGHT
  9378. #if SLRESOURCES
  9379. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  9380. #else
  9381. return true;
  9382. #endif
  9383. #else
  9384. return ex.ParamName == expected;
  9385. #endif
  9386. }
  9387. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  9388. {
  9389. #if SILVERLIGHT
  9390. #if SLRESOURCES
  9391. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  9392. #else
  9393. return true;
  9394. #endif
  9395. #else
  9396. return ex.ParamName == expected;
  9397. #endif
  9398. }
  9399. }
  9400. public static class Verification
  9401. {
  9402. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  9403. {
  9404. if (!(result.NodeType == et))
  9405. {
  9406. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9407. return 1;
  9408. }
  9409. if (!(result.Type == type))
  9410. {
  9411. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9412. return 1;
  9413. }
  9414. if (val == null)
  9415. {
  9416. if (result.Value != null) return 1;
  9417. }
  9418. else
  9419. {
  9420. if (!(result.Value.Equals(val))) return 1;
  9421. }
  9422. if (!(result.ToString() == str)) return 1;
  9423. return 0;
  9424. }
  9425. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  9426. {
  9427. if (!(result.NodeType == et))
  9428. {
  9429. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9430. return 1;
  9431. }
  9432. if (!(result.Type == type))
  9433. {
  9434. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9435. return 1;
  9436. }
  9437. if (operand == null)
  9438. {
  9439. if (result.Operand != null) return 1;
  9440. }
  9441. else
  9442. {
  9443. if (!(result.Operand.Equals(operand))) return 1;
  9444. }
  9445. if (!(result.ToString() == str))
  9446. {
  9447. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  9448. return 1;
  9449. }
  9450. if (result.Method != mi) return 1;
  9451. if (result.IsLifted != islifted) return 1;
  9452. if (result.IsLiftedToNull != isliftedtonull) return 1;
  9453. return 0;
  9454. }
  9455. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  9456. {
  9457. if (!(result.NodeType == et))
  9458. {
  9459. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9460. return 1;
  9461. }
  9462. if (!(result.Type == type))
  9463. {
  9464. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9465. return 1;
  9466. }
  9467. if (left == null)
  9468. {
  9469. if (result.Left != null)
  9470. {
  9471. Console.WriteLine("left was null");
  9472. return 1;
  9473. }
  9474. }
  9475. else
  9476. {
  9477. if (!(result.Left.Equals(left)))
  9478. {
  9479. Console.WriteLine("left was different");
  9480. return 1;
  9481. }
  9482. }
  9483. if (right == null)
  9484. {
  9485. if (result.Right != null) return 1;
  9486. }
  9487. else
  9488. {
  9489. if (!(result.Right.Equals(right))) return 1;
  9490. }
  9491. if (!(result.ToString() == str))
  9492. {
  9493. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  9494. return 1;
  9495. }
  9496. if (result.Method != mi) return 1;
  9497. if (result.IsLifted != islifted) return 1;
  9498. if (result.IsLiftedToNull != isliftedtonull) return 1;
  9499. if (result.Conversion != null) return 1;
  9500. return 0;
  9501. }
  9502. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  9503. {
  9504. if (!(result.NodeType == et))
  9505. {
  9506. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9507. return 1;
  9508. }
  9509. if (!(result.Type == type))
  9510. {
  9511. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9512. return 1;
  9513. }
  9514. if (left == null)
  9515. {
  9516. if (result.Left != null) return 1;
  9517. }
  9518. else
  9519. {
  9520. if (!(result.Left.Equals(left))) return 1;
  9521. }
  9522. if (right == null)
  9523. {
  9524. if (result.Right != null) return 1;
  9525. }
  9526. else
  9527. {
  9528. if (!(result.Right.Equals(right))) return 1;
  9529. }
  9530. if (!(result.ToString() == str)) return 1;
  9531. if (result.Method != mi) return 1;
  9532. if (result.IsLifted != islifted) return 1;
  9533. if (result.IsLiftedToNull != isliftedtonull) return 1;
  9534. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  9535. return 0;
  9536. }
  9537. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  9538. {
  9539. if (!(result.NodeType == et))
  9540. {
  9541. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9542. return 1;
  9543. }
  9544. if (!(result.Type == type))
  9545. {
  9546. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9547. return 1;
  9548. }
  9549. if (!(result.Method == method)) return 1;
  9550. if (obj == null)
  9551. {
  9552. if (result.Object != null)
  9553. {
  9554. Console.WriteLine("Expected object to be null.");
  9555. return 1;
  9556. }
  9557. }
  9558. else
  9559. {
  9560. if (!(result.Object.Equals(obj)))
  9561. {
  9562. Console.WriteLine("Object on which call is made is different from the result.");
  9563. return 1;
  9564. }
  9565. }
  9566. if (!(result.ToString() == str))
  9567. {
  9568. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  9569. return 1;
  9570. }
  9571. if (result.Arguments.Count != arguments.Length) return 1;
  9572. for (int i = 0; i < arguments.Length; i++)
  9573. {
  9574. if (result.Arguments[i] != arguments[i]) return 1;
  9575. }
  9576. return 0;
  9577. }
  9578. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  9579. {
  9580. if (!(result.NodeType == et))
  9581. {
  9582. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9583. return 1;
  9584. }
  9585. if (!(result.Type == type))
  9586. {
  9587. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9588. return 1;
  9589. }
  9590. if (expr == null)
  9591. {
  9592. Console.WriteLine("expr was null.");
  9593. if (result.Expression != null) return 1;
  9594. }
  9595. else
  9596. {
  9597. if (!(result.Expression.Equals(expr)))
  9598. {
  9599. return 1;
  9600. }
  9601. }
  9602. if (!(result.TypeOperand == typeop)) return 1;
  9603. if (!(result.ToString() == str))
  9604. {
  9605. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  9606. return 1;
  9607. }
  9608. return 0;
  9609. }
  9610. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  9611. {
  9612. if (!(result.NodeType == et))
  9613. {
  9614. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9615. return 1;
  9616. }
  9617. if (!(result.Type == type))
  9618. {
  9619. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9620. return 1;
  9621. }
  9622. if (test == null)
  9623. {
  9624. if (result.Test != null) return 1;
  9625. }
  9626. else
  9627. {
  9628. if (!(result.Test.Equals(test))) return 1;
  9629. }
  9630. if (ifTrue == null)
  9631. {
  9632. if (result.IfTrue != null) return 1;
  9633. }
  9634. else
  9635. {
  9636. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  9637. }
  9638. if (ifFalse == null)
  9639. {
  9640. if (result.IfFalse != null) return 1;
  9641. }
  9642. else
  9643. {
  9644. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  9645. }
  9646. if (!(result.ToString() == str)) return 1;
  9647. return 0;
  9648. }
  9649. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  9650. {
  9651. if (!(result.NodeType == et))
  9652. {
  9653. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9654. return 1;
  9655. }
  9656. if (!(result.Type == type))
  9657. {
  9658. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9659. return 1;
  9660. }
  9661. if (exp_expr == null)
  9662. {
  9663. if (result.Expression != null)
  9664. {
  9665. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  9666. return 1;
  9667. }
  9668. }
  9669. else
  9670. {
  9671. if (!(result.Expression.Equals(exp_expr)))
  9672. {
  9673. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  9674. return 1;
  9675. }
  9676. }
  9677. if (!(result.Member == exp_member))
  9678. {
  9679. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  9680. return 1;
  9681. }
  9682. if (!(result.ToString() == str))
  9683. {
  9684. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9685. return 1;
  9686. }
  9687. return 0;
  9688. }
  9689. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  9690. {
  9691. if (!(result.NodeType == et))
  9692. {
  9693. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9694. return 1;
  9695. }
  9696. if (!(result.Type == type))
  9697. {
  9698. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9699. return 1;
  9700. }
  9701. if (!(result.Constructor == constructor))
  9702. {
  9703. Console.WriteLine("Unexpected constructor");
  9704. return 1;
  9705. }
  9706. if (!(result.ToString() == str))
  9707. {
  9708. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9709. return 1;
  9710. }
  9711. if (arguments == null)
  9712. {
  9713. if (result.Arguments.Count != 0)
  9714. {
  9715. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  9716. return 1;
  9717. }
  9718. }
  9719. else
  9720. {
  9721. if (result.Arguments.Count != arguments.Length)
  9722. {
  9723. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  9724. return 1;
  9725. }
  9726. for (int i = 0; i < arguments.Length; i++)
  9727. {
  9728. if (result.Arguments[i] != arguments[i])
  9729. {
  9730. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  9731. return 1;
  9732. }
  9733. }
  9734. }
  9735. if (result.Members == null)
  9736. {
  9737. Console.WriteLine("result.Members was null");
  9738. return 1;
  9739. }
  9740. if (members == null)
  9741. {
  9742. if (result.Members.Count != 0)
  9743. {
  9744. Console.WriteLine("Got more than zero members");
  9745. return 1;
  9746. }
  9747. }
  9748. else
  9749. {
  9750. if (result.Members.Count != members.Length)
  9751. {
  9752. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  9753. return 1;
  9754. }
  9755. for (int i = 0; i < members.Length; i++)
  9756. {
  9757. if (result.Members[i] != members[i])
  9758. {
  9759. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  9760. return 1;
  9761. }
  9762. }
  9763. }
  9764. return 0;
  9765. }
  9766. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  9767. {
  9768. if (!(result.NodeType == et))
  9769. {
  9770. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9771. return 1;
  9772. }
  9773. if (!(result.Type == type))
  9774. {
  9775. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9776. return 1;
  9777. }
  9778. if (!(result.Constructor == constructor))
  9779. {
  9780. Console.WriteLine("Constructor is different from expected.");
  9781. return 1;
  9782. }
  9783. if (!(result.ToString() == str))
  9784. {
  9785. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9786. return 1;
  9787. }
  9788. if (result.Arguments.Count != arguments.Length)
  9789. {
  9790. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  9791. return 1;
  9792. }
  9793. for (int i = 0; i < arguments.Length; i++)
  9794. {
  9795. if (result.Arguments[i] != arguments[i])
  9796. {
  9797. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  9798. return 1;
  9799. }
  9800. }
  9801. if (result.Members != null)
  9802. {
  9803. Console.WriteLine("result.Members isn't null");
  9804. return 1;
  9805. }
  9806. return 0;
  9807. }
  9808. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  9809. {
  9810. if (!(result.NodeType == et))
  9811. {
  9812. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9813. return 1;
  9814. }
  9815. if (!(result.Type == type))
  9816. {
  9817. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9818. return 1;
  9819. }
  9820. if (!(result.NewExpression == newExpression)) return 1;
  9821. if (!(result.ToString() == str))
  9822. {
  9823. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9824. return 1;
  9825. }
  9826. if (result.Initializers.Count != initializers.Length) return 1;
  9827. for (int i = 0; i < initializers.Length; i++)
  9828. {
  9829. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  9830. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  9831. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  9832. {
  9833. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  9834. }
  9835. }
  9836. return 0;
  9837. }
  9838. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  9839. {
  9840. if (result.AddMethod != exp_mi) return 1;
  9841. if (!(result.ToString() == str))
  9842. {
  9843. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9844. return 1;
  9845. }
  9846. if (result.Arguments.Count != args.Length) return 1;
  9847. for (int i = 0; i < args.Length; i++)
  9848. {
  9849. if (result.Arguments[i] != args[i]) return 1;
  9850. }
  9851. return 0;
  9852. }
  9853. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  9854. {
  9855. if (!(result.BindingType == bt)) return 1;
  9856. if (!(result.Expression == expr)) return 1;
  9857. if (!(result.Member.Equals(member))) return 1;
  9858. if (!(result.ToString() == str))
  9859. {
  9860. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9861. return 1;
  9862. }
  9863. return 0;
  9864. }
  9865. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  9866. {
  9867. if (!(result.BindingType == bt)) return 1;
  9868. if (!(result.Member.Equals(member))) return 1;
  9869. if (!(result.ToString() == str))
  9870. {
  9871. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9872. return 1;
  9873. }
  9874. if (result.Initializers.Count != initializers.Length) return 1;
  9875. for (int i = 0; i < initializers.Length; i++)
  9876. {
  9877. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  9878. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  9879. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  9880. {
  9881. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  9882. }
  9883. }
  9884. return 0;
  9885. }
  9886. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  9887. {
  9888. if (!(result.BindingType == bt)) return 1;
  9889. if (!(result.Member.Equals(member))) return 1;
  9890. if (!(result.ToString() == str))
  9891. {
  9892. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9893. return 1;
  9894. }
  9895. if (result.Bindings.Count != bindings.Length) return 1;
  9896. for (int i = 0; i < bindings.Length; i++)
  9897. {
  9898. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  9899. }
  9900. return 0;
  9901. }
  9902. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  9903. {
  9904. if (!(result.NodeType == et))
  9905. {
  9906. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9907. return 1;
  9908. }
  9909. if (!(result.Type == type))
  9910. {
  9911. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9912. return 1;
  9913. }
  9914. if (!(result.NewExpression.Equals(newExpr))) return 1;
  9915. if (!(result.ToString() == str)) return 1;
  9916. if (result.Bindings.Count != bindings.Length) return 1;
  9917. for (int i = 0; i < bindings.Length; i++)
  9918. {
  9919. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  9920. }
  9921. return 0;
  9922. }
  9923. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  9924. {
  9925. if (!(result.NodeType == et))
  9926. {
  9927. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9928. return 1;
  9929. }
  9930. if (!(result.Type == type))
  9931. {
  9932. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9933. return 1;
  9934. }
  9935. if (result.Expressions.Count != expr.Length) return 1;
  9936. for (int i = 0; i < expr.Length; i++)
  9937. {
  9938. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  9939. }
  9940. if (!(result.ToString() == str))
  9941. {
  9942. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9943. return 1;
  9944. }
  9945. return 0;
  9946. }
  9947. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  9948. {
  9949. if (!(result.NodeType == et))
  9950. {
  9951. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9952. return 1;
  9953. }
  9954. if (!(result.Type == type))
  9955. {
  9956. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9957. return 1;
  9958. }
  9959. if (!(result.Name == name)) return 1;
  9960. if (!(result.ToString() == str))
  9961. {
  9962. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9963. return 1;
  9964. }
  9965. return 0;
  9966. }
  9967. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  9968. {
  9969. if (!(result.NodeType == et))
  9970. {
  9971. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  9972. return 1;
  9973. }
  9974. if (!(result.Type == type))
  9975. {
  9976. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  9977. return 1;
  9978. }
  9979. if (expr == null)
  9980. {
  9981. if (result.Body != null) return 1;
  9982. }
  9983. else
  9984. {
  9985. if (!(result.Body.Equals(expr))) return 1;
  9986. }
  9987. if (result.Parameters.Count != parms.Length) return 1;
  9988. for (int i = 0; i < parms.Length; i++)
  9989. {
  9990. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  9991. }
  9992. if (!(result.ToString() == str))
  9993. {
  9994. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  9995. return 1;
  9996. }
  9997. return 0;
  9998. }
  9999. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  10000. {
  10001. if (!(result.NodeType == et))
  10002. {
  10003. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10004. return 1;
  10005. }
  10006. if (!(result.Type == type))
  10007. {
  10008. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10009. return 1;
  10010. }
  10011. if (expr == null)
  10012. {
  10013. if (result.Expression != null) return 1;
  10014. }
  10015. else
  10016. {
  10017. if (!(result.Expression.Equals(expr))) return 1;
  10018. }
  10019. if (result.Arguments.Count != args.Length) return 1;
  10020. for (int i = 0; i < args.Length; i++)
  10021. {
  10022. if (!(result.Arguments[i].Equals(args[i])))
  10023. {
  10024. return 1;
  10025. }
  10026. }
  10027. if (result.ToString() != str)
  10028. {
  10029. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10030. return 1;
  10031. }
  10032. return 0;
  10033. }
  10034. }
  10035. namespace Not
  10036. {
  10037. // Declaring user-defined types for testing
  10038. struct TC1
  10039. {
  10040. public static TC1 operator !(TC1 c)
  10041. {
  10042. return new TC1();
  10043. }
  10044. public static TC1 operator ~(TC1 c)
  10045. {
  10046. return new TC1();
  10047. }
  10048. }
  10049. struct TC2
  10050. {
  10051. public static TC2 operator ~(TC2 c)
  10052. {
  10053. return new TC2();
  10054. }
  10055. }
  10056. struct TC3
  10057. {
  10058. public static TC3 Meth1(TC3 c)
  10059. {
  10060. return new TC3();
  10061. }
  10062. }
  10063. }
  10064. }
  10065. //-------- Scenario 796
  10066. namespace Scenario796
  10067. {
  10068. namespace Not
  10069. {
  10070. public class Test
  10071. {
  10072. // Overload-2: Test for functionality: Passing non-null methodinfo without lifting
  10073. public static int Test14()
  10074. {
  10075. TC3 ctest = new TC3();
  10076. ConstantExpression ce = Expression.Constant(ctest, typeof(TC3));
  10077. Type exp_type = typeof(TC3);
  10078. ExpressionType exp_et = ExpressionType.Not;
  10079. string exp_str = "Not(" + ce.ToString() + ")";
  10080. Expression exp_operand = ce;
  10081. MethodInfo exp_mi = typeof(TC3).GetMethod("Meth1");
  10082. UnaryExpression result = Expression.Not(ce, exp_mi);
  10083. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, false, false);
  10084. }
  10085. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not14__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  10086. public static Expression Not14__()
  10087. {
  10088. if (Main() != 0)
  10089. {
  10090. throw new Exception();
  10091. }
  10092. else
  10093. {
  10094. return Expression.Constant(0);
  10095. }
  10096. }
  10097. public static int Main()
  10098. {
  10099. return Test14();
  10100. }
  10101. }
  10102. }
  10103. public static class Extension
  10104. {
  10105. public static bool CompareParamName(this ArgumentException ex, string expected)
  10106. {
  10107. #if SILVERLIGHT
  10108. #if SLRESOURCES
  10109. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  10110. #else
  10111. return true;
  10112. #endif
  10113. #else
  10114. return ex.ParamName == expected;
  10115. #endif
  10116. }
  10117. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  10118. {
  10119. #if SILVERLIGHT
  10120. #if SLRESOURCES
  10121. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  10122. #else
  10123. return true;
  10124. #endif
  10125. #else
  10126. return ex.ParamName == expected;
  10127. #endif
  10128. }
  10129. }
  10130. public static class Verification
  10131. {
  10132. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  10133. {
  10134. if (!(result.NodeType == et))
  10135. {
  10136. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10137. return 1;
  10138. }
  10139. if (!(result.Type == type))
  10140. {
  10141. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10142. return 1;
  10143. }
  10144. if (val == null)
  10145. {
  10146. if (result.Value != null) return 1;
  10147. }
  10148. else
  10149. {
  10150. if (!(result.Value.Equals(val))) return 1;
  10151. }
  10152. if (!(result.ToString() == str)) return 1;
  10153. return 0;
  10154. }
  10155. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  10156. {
  10157. if (!(result.NodeType == et))
  10158. {
  10159. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10160. return 1;
  10161. }
  10162. if (!(result.Type == type))
  10163. {
  10164. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10165. return 1;
  10166. }
  10167. if (operand == null)
  10168. {
  10169. if (result.Operand != null) return 1;
  10170. }
  10171. else
  10172. {
  10173. if (!(result.Operand.Equals(operand))) return 1;
  10174. }
  10175. if (!(result.ToString() == str))
  10176. {
  10177. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10178. return 1;
  10179. }
  10180. if (result.Method != mi) return 1;
  10181. if (result.IsLifted != islifted) return 1;
  10182. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10183. return 0;
  10184. }
  10185. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  10186. {
  10187. if (!(result.NodeType == et))
  10188. {
  10189. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10190. return 1;
  10191. }
  10192. if (!(result.Type == type))
  10193. {
  10194. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10195. return 1;
  10196. }
  10197. if (left == null)
  10198. {
  10199. if (result.Left != null)
  10200. {
  10201. Console.WriteLine("left was null");
  10202. return 1;
  10203. }
  10204. }
  10205. else
  10206. {
  10207. if (!(result.Left.Equals(left)))
  10208. {
  10209. Console.WriteLine("left was different");
  10210. return 1;
  10211. }
  10212. }
  10213. if (right == null)
  10214. {
  10215. if (result.Right != null) return 1;
  10216. }
  10217. else
  10218. {
  10219. if (!(result.Right.Equals(right))) return 1;
  10220. }
  10221. if (!(result.ToString() == str))
  10222. {
  10223. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10224. return 1;
  10225. }
  10226. if (result.Method != mi) return 1;
  10227. if (result.IsLifted != islifted) return 1;
  10228. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10229. if (result.Conversion != null) return 1;
  10230. return 0;
  10231. }
  10232. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  10233. {
  10234. if (!(result.NodeType == et))
  10235. {
  10236. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10237. return 1;
  10238. }
  10239. if (!(result.Type == type))
  10240. {
  10241. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10242. return 1;
  10243. }
  10244. if (left == null)
  10245. {
  10246. if (result.Left != null) return 1;
  10247. }
  10248. else
  10249. {
  10250. if (!(result.Left.Equals(left))) return 1;
  10251. }
  10252. if (right == null)
  10253. {
  10254. if (result.Right != null) return 1;
  10255. }
  10256. else
  10257. {
  10258. if (!(result.Right.Equals(right))) return 1;
  10259. }
  10260. if (!(result.ToString() == str)) return 1;
  10261. if (result.Method != mi) return 1;
  10262. if (result.IsLifted != islifted) return 1;
  10263. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10264. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  10265. return 0;
  10266. }
  10267. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  10268. {
  10269. if (!(result.NodeType == et))
  10270. {
  10271. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10272. return 1;
  10273. }
  10274. if (!(result.Type == type))
  10275. {
  10276. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10277. return 1;
  10278. }
  10279. if (!(result.Method == method)) return 1;
  10280. if (obj == null)
  10281. {
  10282. if (result.Object != null)
  10283. {
  10284. Console.WriteLine("Expected object to be null.");
  10285. return 1;
  10286. }
  10287. }
  10288. else
  10289. {
  10290. if (!(result.Object.Equals(obj)))
  10291. {
  10292. Console.WriteLine("Object on which call is made is different from the result.");
  10293. return 1;
  10294. }
  10295. }
  10296. if (!(result.ToString() == str))
  10297. {
  10298. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10299. return 1;
  10300. }
  10301. if (result.Arguments.Count != arguments.Length) return 1;
  10302. for (int i = 0; i < arguments.Length; i++)
  10303. {
  10304. if (result.Arguments[i] != arguments[i]) return 1;
  10305. }
  10306. return 0;
  10307. }
  10308. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  10309. {
  10310. if (!(result.NodeType == et))
  10311. {
  10312. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10313. return 1;
  10314. }
  10315. if (!(result.Type == type))
  10316. {
  10317. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10318. return 1;
  10319. }
  10320. if (expr == null)
  10321. {
  10322. Console.WriteLine("expr was null.");
  10323. if (result.Expression != null) return 1;
  10324. }
  10325. else
  10326. {
  10327. if (!(result.Expression.Equals(expr)))
  10328. {
  10329. return 1;
  10330. }
  10331. }
  10332. if (!(result.TypeOperand == typeop)) return 1;
  10333. if (!(result.ToString() == str))
  10334. {
  10335. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10336. return 1;
  10337. }
  10338. return 0;
  10339. }
  10340. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  10341. {
  10342. if (!(result.NodeType == et))
  10343. {
  10344. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10345. return 1;
  10346. }
  10347. if (!(result.Type == type))
  10348. {
  10349. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10350. return 1;
  10351. }
  10352. if (test == null)
  10353. {
  10354. if (result.Test != null) return 1;
  10355. }
  10356. else
  10357. {
  10358. if (!(result.Test.Equals(test))) return 1;
  10359. }
  10360. if (ifTrue == null)
  10361. {
  10362. if (result.IfTrue != null) return 1;
  10363. }
  10364. else
  10365. {
  10366. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  10367. }
  10368. if (ifFalse == null)
  10369. {
  10370. if (result.IfFalse != null) return 1;
  10371. }
  10372. else
  10373. {
  10374. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  10375. }
  10376. if (!(result.ToString() == str)) return 1;
  10377. return 0;
  10378. }
  10379. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  10380. {
  10381. if (!(result.NodeType == et))
  10382. {
  10383. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10384. return 1;
  10385. }
  10386. if (!(result.Type == type))
  10387. {
  10388. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10389. return 1;
  10390. }
  10391. if (exp_expr == null)
  10392. {
  10393. if (result.Expression != null)
  10394. {
  10395. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  10396. return 1;
  10397. }
  10398. }
  10399. else
  10400. {
  10401. if (!(result.Expression.Equals(exp_expr)))
  10402. {
  10403. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  10404. return 1;
  10405. }
  10406. }
  10407. if (!(result.Member == exp_member))
  10408. {
  10409. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  10410. return 1;
  10411. }
  10412. if (!(result.ToString() == str))
  10413. {
  10414. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10415. return 1;
  10416. }
  10417. return 0;
  10418. }
  10419. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  10420. {
  10421. if (!(result.NodeType == et))
  10422. {
  10423. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10424. return 1;
  10425. }
  10426. if (!(result.Type == type))
  10427. {
  10428. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10429. return 1;
  10430. }
  10431. if (!(result.Constructor == constructor))
  10432. {
  10433. Console.WriteLine("Unexpected constructor");
  10434. return 1;
  10435. }
  10436. if (!(result.ToString() == str))
  10437. {
  10438. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10439. return 1;
  10440. }
  10441. if (arguments == null)
  10442. {
  10443. if (result.Arguments.Count != 0)
  10444. {
  10445. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  10446. return 1;
  10447. }
  10448. }
  10449. else
  10450. {
  10451. if (result.Arguments.Count != arguments.Length)
  10452. {
  10453. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  10454. return 1;
  10455. }
  10456. for (int i = 0; i < arguments.Length; i++)
  10457. {
  10458. if (result.Arguments[i] != arguments[i])
  10459. {
  10460. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  10461. return 1;
  10462. }
  10463. }
  10464. }
  10465. if (result.Members == null)
  10466. {
  10467. Console.WriteLine("result.Members was null");
  10468. return 1;
  10469. }
  10470. if (members == null)
  10471. {
  10472. if (result.Members.Count != 0)
  10473. {
  10474. Console.WriteLine("Got more than zero members");
  10475. return 1;
  10476. }
  10477. }
  10478. else
  10479. {
  10480. if (result.Members.Count != members.Length)
  10481. {
  10482. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  10483. return 1;
  10484. }
  10485. for (int i = 0; i < members.Length; i++)
  10486. {
  10487. if (result.Members[i] != members[i])
  10488. {
  10489. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  10490. return 1;
  10491. }
  10492. }
  10493. }
  10494. return 0;
  10495. }
  10496. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  10497. {
  10498. if (!(result.NodeType == et))
  10499. {
  10500. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10501. return 1;
  10502. }
  10503. if (!(result.Type == type))
  10504. {
  10505. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10506. return 1;
  10507. }
  10508. if (!(result.Constructor == constructor))
  10509. {
  10510. Console.WriteLine("Constructor is different from expected.");
  10511. return 1;
  10512. }
  10513. if (!(result.ToString() == str))
  10514. {
  10515. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10516. return 1;
  10517. }
  10518. if (result.Arguments.Count != arguments.Length)
  10519. {
  10520. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  10521. return 1;
  10522. }
  10523. for (int i = 0; i < arguments.Length; i++)
  10524. {
  10525. if (result.Arguments[i] != arguments[i])
  10526. {
  10527. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  10528. return 1;
  10529. }
  10530. }
  10531. if (result.Members != null)
  10532. {
  10533. Console.WriteLine("result.Members isn't null");
  10534. return 1;
  10535. }
  10536. return 0;
  10537. }
  10538. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  10539. {
  10540. if (!(result.NodeType == et))
  10541. {
  10542. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10543. return 1;
  10544. }
  10545. if (!(result.Type == type))
  10546. {
  10547. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10548. return 1;
  10549. }
  10550. if (!(result.NewExpression == newExpression)) return 1;
  10551. if (!(result.ToString() == str))
  10552. {
  10553. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10554. return 1;
  10555. }
  10556. if (result.Initializers.Count != initializers.Length) return 1;
  10557. for (int i = 0; i < initializers.Length; i++)
  10558. {
  10559. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  10560. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  10561. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  10562. {
  10563. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  10564. }
  10565. }
  10566. return 0;
  10567. }
  10568. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  10569. {
  10570. if (result.AddMethod != exp_mi) return 1;
  10571. if (!(result.ToString() == str))
  10572. {
  10573. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10574. return 1;
  10575. }
  10576. if (result.Arguments.Count != args.Length) return 1;
  10577. for (int i = 0; i < args.Length; i++)
  10578. {
  10579. if (result.Arguments[i] != args[i]) return 1;
  10580. }
  10581. return 0;
  10582. }
  10583. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  10584. {
  10585. if (!(result.BindingType == bt)) return 1;
  10586. if (!(result.Expression == expr)) return 1;
  10587. if (!(result.Member.Equals(member))) return 1;
  10588. if (!(result.ToString() == str))
  10589. {
  10590. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10591. return 1;
  10592. }
  10593. return 0;
  10594. }
  10595. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  10596. {
  10597. if (!(result.BindingType == bt)) return 1;
  10598. if (!(result.Member.Equals(member))) return 1;
  10599. if (!(result.ToString() == str))
  10600. {
  10601. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10602. return 1;
  10603. }
  10604. if (result.Initializers.Count != initializers.Length) return 1;
  10605. for (int i = 0; i < initializers.Length; i++)
  10606. {
  10607. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  10608. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  10609. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  10610. {
  10611. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  10612. }
  10613. }
  10614. return 0;
  10615. }
  10616. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  10617. {
  10618. if (!(result.BindingType == bt)) return 1;
  10619. if (!(result.Member.Equals(member))) return 1;
  10620. if (!(result.ToString() == str))
  10621. {
  10622. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10623. return 1;
  10624. }
  10625. if (result.Bindings.Count != bindings.Length) return 1;
  10626. for (int i = 0; i < bindings.Length; i++)
  10627. {
  10628. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  10629. }
  10630. return 0;
  10631. }
  10632. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  10633. {
  10634. if (!(result.NodeType == et))
  10635. {
  10636. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10637. return 1;
  10638. }
  10639. if (!(result.Type == type))
  10640. {
  10641. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10642. return 1;
  10643. }
  10644. if (!(result.NewExpression.Equals(newExpr))) return 1;
  10645. if (!(result.ToString() == str)) return 1;
  10646. if (result.Bindings.Count != bindings.Length) return 1;
  10647. for (int i = 0; i < bindings.Length; i++)
  10648. {
  10649. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  10650. }
  10651. return 0;
  10652. }
  10653. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  10654. {
  10655. if (!(result.NodeType == et))
  10656. {
  10657. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10658. return 1;
  10659. }
  10660. if (!(result.Type == type))
  10661. {
  10662. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10663. return 1;
  10664. }
  10665. if (result.Expressions.Count != expr.Length) return 1;
  10666. for (int i = 0; i < expr.Length; i++)
  10667. {
  10668. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  10669. }
  10670. if (!(result.ToString() == str))
  10671. {
  10672. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10673. return 1;
  10674. }
  10675. return 0;
  10676. }
  10677. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  10678. {
  10679. if (!(result.NodeType == et))
  10680. {
  10681. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10682. return 1;
  10683. }
  10684. if (!(result.Type == type))
  10685. {
  10686. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10687. return 1;
  10688. }
  10689. if (!(result.Name == name)) return 1;
  10690. if (!(result.ToString() == str))
  10691. {
  10692. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10693. return 1;
  10694. }
  10695. return 0;
  10696. }
  10697. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  10698. {
  10699. if (!(result.NodeType == et))
  10700. {
  10701. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10702. return 1;
  10703. }
  10704. if (!(result.Type == type))
  10705. {
  10706. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10707. return 1;
  10708. }
  10709. if (expr == null)
  10710. {
  10711. if (result.Body != null) return 1;
  10712. }
  10713. else
  10714. {
  10715. if (!(result.Body.Equals(expr))) return 1;
  10716. }
  10717. if (result.Parameters.Count != parms.Length) return 1;
  10718. for (int i = 0; i < parms.Length; i++)
  10719. {
  10720. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  10721. }
  10722. if (!(result.ToString() == str))
  10723. {
  10724. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  10725. return 1;
  10726. }
  10727. return 0;
  10728. }
  10729. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  10730. {
  10731. if (!(result.NodeType == et))
  10732. {
  10733. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10734. return 1;
  10735. }
  10736. if (!(result.Type == type))
  10737. {
  10738. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10739. return 1;
  10740. }
  10741. if (expr == null)
  10742. {
  10743. if (result.Expression != null) return 1;
  10744. }
  10745. else
  10746. {
  10747. if (!(result.Expression.Equals(expr))) return 1;
  10748. }
  10749. if (result.Arguments.Count != args.Length) return 1;
  10750. for (int i = 0; i < args.Length; i++)
  10751. {
  10752. if (!(result.Arguments[i].Equals(args[i])))
  10753. {
  10754. return 1;
  10755. }
  10756. }
  10757. if (result.ToString() != str)
  10758. {
  10759. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10760. return 1;
  10761. }
  10762. return 0;
  10763. }
  10764. }
  10765. namespace Not
  10766. {
  10767. // Declaring user-defined types for testing
  10768. struct TC1
  10769. {
  10770. public static TC1 operator !(TC1 c)
  10771. {
  10772. return new TC1();
  10773. }
  10774. public static TC1 operator ~(TC1 c)
  10775. {
  10776. return new TC1();
  10777. }
  10778. }
  10779. struct TC2
  10780. {
  10781. public static TC2 operator ~(TC2 c)
  10782. {
  10783. return new TC2();
  10784. }
  10785. }
  10786. struct TC3
  10787. {
  10788. public static TC3 Meth1(TC3 c)
  10789. {
  10790. return new TC3();
  10791. }
  10792. }
  10793. }
  10794. }
  10795. //-------- Scenario 797
  10796. namespace Scenario797
  10797. {
  10798. namespace Not
  10799. {
  10800. public class Test
  10801. {
  10802. // Overload-2: Test for functionality: Passing non-null methodinfo with lifting
  10803. public static int Test15()
  10804. {
  10805. TC3? ctest = new TC3?();
  10806. ConstantExpression ce = Expression.Constant(ctest, typeof(TC3?));
  10807. Type exp_type = typeof(TC3?);
  10808. ExpressionType exp_et = ExpressionType.Not;
  10809. string exp_str = "Not(" + ce.ToString() + ")";
  10810. Expression exp_operand = ce;
  10811. MethodInfo exp_mi = typeof(TC3).GetMethod("Meth1");
  10812. UnaryExpression result = Expression.Not(ce, exp_mi);
  10813. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, exp_mi, true, true);
  10814. }
  10815. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not15__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  10816. public static Expression Not15__()
  10817. {
  10818. if (Main() != 0)
  10819. {
  10820. throw new Exception();
  10821. }
  10822. else
  10823. {
  10824. return Expression.Constant(0);
  10825. }
  10826. }
  10827. public static int Main()
  10828. {
  10829. return Test15();
  10830. }
  10831. }
  10832. }
  10833. public static class Extension
  10834. {
  10835. public static bool CompareParamName(this ArgumentException ex, string expected)
  10836. {
  10837. #if SILVERLIGHT
  10838. #if SLRESOURCES
  10839. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  10840. #else
  10841. return true;
  10842. #endif
  10843. #else
  10844. return ex.ParamName == expected;
  10845. #endif
  10846. }
  10847. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  10848. {
  10849. #if SILVERLIGHT
  10850. #if SLRESOURCES
  10851. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  10852. #else
  10853. return true;
  10854. #endif
  10855. #else
  10856. return ex.ParamName == expected;
  10857. #endif
  10858. }
  10859. }
  10860. public static class Verification
  10861. {
  10862. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  10863. {
  10864. if (!(result.NodeType == et))
  10865. {
  10866. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10867. return 1;
  10868. }
  10869. if (!(result.Type == type))
  10870. {
  10871. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10872. return 1;
  10873. }
  10874. if (val == null)
  10875. {
  10876. if (result.Value != null) return 1;
  10877. }
  10878. else
  10879. {
  10880. if (!(result.Value.Equals(val))) return 1;
  10881. }
  10882. if (!(result.ToString() == str)) return 1;
  10883. return 0;
  10884. }
  10885. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  10886. {
  10887. if (!(result.NodeType == et))
  10888. {
  10889. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10890. return 1;
  10891. }
  10892. if (!(result.Type == type))
  10893. {
  10894. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10895. return 1;
  10896. }
  10897. if (operand == null)
  10898. {
  10899. if (result.Operand != null) return 1;
  10900. }
  10901. else
  10902. {
  10903. if (!(result.Operand.Equals(operand))) return 1;
  10904. }
  10905. if (!(result.ToString() == str))
  10906. {
  10907. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10908. return 1;
  10909. }
  10910. if (result.Method != mi) return 1;
  10911. if (result.IsLifted != islifted) return 1;
  10912. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10913. return 0;
  10914. }
  10915. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  10916. {
  10917. if (!(result.NodeType == et))
  10918. {
  10919. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10920. return 1;
  10921. }
  10922. if (!(result.Type == type))
  10923. {
  10924. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10925. return 1;
  10926. }
  10927. if (left == null)
  10928. {
  10929. if (result.Left != null)
  10930. {
  10931. Console.WriteLine("left was null");
  10932. return 1;
  10933. }
  10934. }
  10935. else
  10936. {
  10937. if (!(result.Left.Equals(left)))
  10938. {
  10939. Console.WriteLine("left was different");
  10940. return 1;
  10941. }
  10942. }
  10943. if (right == null)
  10944. {
  10945. if (result.Right != null) return 1;
  10946. }
  10947. else
  10948. {
  10949. if (!(result.Right.Equals(right))) return 1;
  10950. }
  10951. if (!(result.ToString() == str))
  10952. {
  10953. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  10954. return 1;
  10955. }
  10956. if (result.Method != mi) return 1;
  10957. if (result.IsLifted != islifted) return 1;
  10958. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10959. if (result.Conversion != null) return 1;
  10960. return 0;
  10961. }
  10962. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  10963. {
  10964. if (!(result.NodeType == et))
  10965. {
  10966. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  10967. return 1;
  10968. }
  10969. if (!(result.Type == type))
  10970. {
  10971. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  10972. return 1;
  10973. }
  10974. if (left == null)
  10975. {
  10976. if (result.Left != null) return 1;
  10977. }
  10978. else
  10979. {
  10980. if (!(result.Left.Equals(left))) return 1;
  10981. }
  10982. if (right == null)
  10983. {
  10984. if (result.Right != null) return 1;
  10985. }
  10986. else
  10987. {
  10988. if (!(result.Right.Equals(right))) return 1;
  10989. }
  10990. if (!(result.ToString() == str)) return 1;
  10991. if (result.Method != mi) return 1;
  10992. if (result.IsLifted != islifted) return 1;
  10993. if (result.IsLiftedToNull != isliftedtonull) return 1;
  10994. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  10995. return 0;
  10996. }
  10997. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  10998. {
  10999. if (!(result.NodeType == et))
  11000. {
  11001. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11002. return 1;
  11003. }
  11004. if (!(result.Type == type))
  11005. {
  11006. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11007. return 1;
  11008. }
  11009. if (!(result.Method == method)) return 1;
  11010. if (obj == null)
  11011. {
  11012. if (result.Object != null)
  11013. {
  11014. Console.WriteLine("Expected object to be null.");
  11015. return 1;
  11016. }
  11017. }
  11018. else
  11019. {
  11020. if (!(result.Object.Equals(obj)))
  11021. {
  11022. Console.WriteLine("Object on which call is made is different from the result.");
  11023. return 1;
  11024. }
  11025. }
  11026. if (!(result.ToString() == str))
  11027. {
  11028. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  11029. return 1;
  11030. }
  11031. if (result.Arguments.Count != arguments.Length) return 1;
  11032. for (int i = 0; i < arguments.Length; i++)
  11033. {
  11034. if (result.Arguments[i] != arguments[i]) return 1;
  11035. }
  11036. return 0;
  11037. }
  11038. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  11039. {
  11040. if (!(result.NodeType == et))
  11041. {
  11042. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11043. return 1;
  11044. }
  11045. if (!(result.Type == type))
  11046. {
  11047. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11048. return 1;
  11049. }
  11050. if (expr == null)
  11051. {
  11052. Console.WriteLine("expr was null.");
  11053. if (result.Expression != null) return 1;
  11054. }
  11055. else
  11056. {
  11057. if (!(result.Expression.Equals(expr)))
  11058. {
  11059. return 1;
  11060. }
  11061. }
  11062. if (!(result.TypeOperand == typeop)) return 1;
  11063. if (!(result.ToString() == str))
  11064. {
  11065. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  11066. return 1;
  11067. }
  11068. return 0;
  11069. }
  11070. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  11071. {
  11072. if (!(result.NodeType == et))
  11073. {
  11074. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11075. return 1;
  11076. }
  11077. if (!(result.Type == type))
  11078. {
  11079. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11080. return 1;
  11081. }
  11082. if (test == null)
  11083. {
  11084. if (result.Test != null) return 1;
  11085. }
  11086. else
  11087. {
  11088. if (!(result.Test.Equals(test))) return 1;
  11089. }
  11090. if (ifTrue == null)
  11091. {
  11092. if (result.IfTrue != null) return 1;
  11093. }
  11094. else
  11095. {
  11096. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  11097. }
  11098. if (ifFalse == null)
  11099. {
  11100. if (result.IfFalse != null) return 1;
  11101. }
  11102. else
  11103. {
  11104. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  11105. }
  11106. if (!(result.ToString() == str)) return 1;
  11107. return 0;
  11108. }
  11109. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  11110. {
  11111. if (!(result.NodeType == et))
  11112. {
  11113. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11114. return 1;
  11115. }
  11116. if (!(result.Type == type))
  11117. {
  11118. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11119. return 1;
  11120. }
  11121. if (exp_expr == null)
  11122. {
  11123. if (result.Expression != null)
  11124. {
  11125. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  11126. return 1;
  11127. }
  11128. }
  11129. else
  11130. {
  11131. if (!(result.Expression.Equals(exp_expr)))
  11132. {
  11133. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  11134. return 1;
  11135. }
  11136. }
  11137. if (!(result.Member == exp_member))
  11138. {
  11139. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  11140. return 1;
  11141. }
  11142. if (!(result.ToString() == str))
  11143. {
  11144. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11145. return 1;
  11146. }
  11147. return 0;
  11148. }
  11149. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  11150. {
  11151. if (!(result.NodeType == et))
  11152. {
  11153. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11154. return 1;
  11155. }
  11156. if (!(result.Type == type))
  11157. {
  11158. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11159. return 1;
  11160. }
  11161. if (!(result.Constructor == constructor))
  11162. {
  11163. Console.WriteLine("Unexpected constructor");
  11164. return 1;
  11165. }
  11166. if (!(result.ToString() == str))
  11167. {
  11168. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11169. return 1;
  11170. }
  11171. if (arguments == null)
  11172. {
  11173. if (result.Arguments.Count != 0)
  11174. {
  11175. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  11176. return 1;
  11177. }
  11178. }
  11179. else
  11180. {
  11181. if (result.Arguments.Count != arguments.Length)
  11182. {
  11183. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  11184. return 1;
  11185. }
  11186. for (int i = 0; i < arguments.Length; i++)
  11187. {
  11188. if (result.Arguments[i] != arguments[i])
  11189. {
  11190. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  11191. return 1;
  11192. }
  11193. }
  11194. }
  11195. if (result.Members == null)
  11196. {
  11197. Console.WriteLine("result.Members was null");
  11198. return 1;
  11199. }
  11200. if (members == null)
  11201. {
  11202. if (result.Members.Count != 0)
  11203. {
  11204. Console.WriteLine("Got more than zero members");
  11205. return 1;
  11206. }
  11207. }
  11208. else
  11209. {
  11210. if (result.Members.Count != members.Length)
  11211. {
  11212. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  11213. return 1;
  11214. }
  11215. for (int i = 0; i < members.Length; i++)
  11216. {
  11217. if (result.Members[i] != members[i])
  11218. {
  11219. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  11220. return 1;
  11221. }
  11222. }
  11223. }
  11224. return 0;
  11225. }
  11226. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  11227. {
  11228. if (!(result.NodeType == et))
  11229. {
  11230. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11231. return 1;
  11232. }
  11233. if (!(result.Type == type))
  11234. {
  11235. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11236. return 1;
  11237. }
  11238. if (!(result.Constructor == constructor))
  11239. {
  11240. Console.WriteLine("Constructor is different from expected.");
  11241. return 1;
  11242. }
  11243. if (!(result.ToString() == str))
  11244. {
  11245. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11246. return 1;
  11247. }
  11248. if (result.Arguments.Count != arguments.Length)
  11249. {
  11250. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  11251. return 1;
  11252. }
  11253. for (int i = 0; i < arguments.Length; i++)
  11254. {
  11255. if (result.Arguments[i] != arguments[i])
  11256. {
  11257. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  11258. return 1;
  11259. }
  11260. }
  11261. if (result.Members != null)
  11262. {
  11263. Console.WriteLine("result.Members isn't null");
  11264. return 1;
  11265. }
  11266. return 0;
  11267. }
  11268. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  11269. {
  11270. if (!(result.NodeType == et))
  11271. {
  11272. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11273. return 1;
  11274. }
  11275. if (!(result.Type == type))
  11276. {
  11277. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11278. return 1;
  11279. }
  11280. if (!(result.NewExpression == newExpression)) return 1;
  11281. if (!(result.ToString() == str))
  11282. {
  11283. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11284. return 1;
  11285. }
  11286. if (result.Initializers.Count != initializers.Length) return 1;
  11287. for (int i = 0; i < initializers.Length; i++)
  11288. {
  11289. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  11290. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  11291. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  11292. {
  11293. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  11294. }
  11295. }
  11296. return 0;
  11297. }
  11298. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  11299. {
  11300. if (result.AddMethod != exp_mi) return 1;
  11301. if (!(result.ToString() == str))
  11302. {
  11303. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11304. return 1;
  11305. }
  11306. if (result.Arguments.Count != args.Length) return 1;
  11307. for (int i = 0; i < args.Length; i++)
  11308. {
  11309. if (result.Arguments[i] != args[i]) return 1;
  11310. }
  11311. return 0;
  11312. }
  11313. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  11314. {
  11315. if (!(result.BindingType == bt)) return 1;
  11316. if (!(result.Expression == expr)) return 1;
  11317. if (!(result.Member.Equals(member))) return 1;
  11318. if (!(result.ToString() == str))
  11319. {
  11320. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11321. return 1;
  11322. }
  11323. return 0;
  11324. }
  11325. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  11326. {
  11327. if (!(result.BindingType == bt)) return 1;
  11328. if (!(result.Member.Equals(member))) return 1;
  11329. if (!(result.ToString() == str))
  11330. {
  11331. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11332. return 1;
  11333. }
  11334. if (result.Initializers.Count != initializers.Length) return 1;
  11335. for (int i = 0; i < initializers.Length; i++)
  11336. {
  11337. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  11338. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  11339. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  11340. {
  11341. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  11342. }
  11343. }
  11344. return 0;
  11345. }
  11346. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  11347. {
  11348. if (!(result.BindingType == bt)) return 1;
  11349. if (!(result.Member.Equals(member))) return 1;
  11350. if (!(result.ToString() == str))
  11351. {
  11352. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11353. return 1;
  11354. }
  11355. if (result.Bindings.Count != bindings.Length) return 1;
  11356. for (int i = 0; i < bindings.Length; i++)
  11357. {
  11358. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  11359. }
  11360. return 0;
  11361. }
  11362. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  11363. {
  11364. if (!(result.NodeType == et))
  11365. {
  11366. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11367. return 1;
  11368. }
  11369. if (!(result.Type == type))
  11370. {
  11371. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11372. return 1;
  11373. }
  11374. if (!(result.NewExpression.Equals(newExpr))) return 1;
  11375. if (!(result.ToString() == str)) return 1;
  11376. if (result.Bindings.Count != bindings.Length) return 1;
  11377. for (int i = 0; i < bindings.Length; i++)
  11378. {
  11379. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  11380. }
  11381. return 0;
  11382. }
  11383. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  11384. {
  11385. if (!(result.NodeType == et))
  11386. {
  11387. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11388. return 1;
  11389. }
  11390. if (!(result.Type == type))
  11391. {
  11392. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11393. return 1;
  11394. }
  11395. if (result.Expressions.Count != expr.Length) return 1;
  11396. for (int i = 0; i < expr.Length; i++)
  11397. {
  11398. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  11399. }
  11400. if (!(result.ToString() == str))
  11401. {
  11402. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11403. return 1;
  11404. }
  11405. return 0;
  11406. }
  11407. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  11408. {
  11409. if (!(result.NodeType == et))
  11410. {
  11411. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11412. return 1;
  11413. }
  11414. if (!(result.Type == type))
  11415. {
  11416. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11417. return 1;
  11418. }
  11419. if (!(result.Name == name)) return 1;
  11420. if (!(result.ToString() == str))
  11421. {
  11422. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11423. return 1;
  11424. }
  11425. return 0;
  11426. }
  11427. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  11428. {
  11429. if (!(result.NodeType == et))
  11430. {
  11431. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11432. return 1;
  11433. }
  11434. if (!(result.Type == type))
  11435. {
  11436. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11437. return 1;
  11438. }
  11439. if (expr == null)
  11440. {
  11441. if (result.Body != null) return 1;
  11442. }
  11443. else
  11444. {
  11445. if (!(result.Body.Equals(expr))) return 1;
  11446. }
  11447. if (result.Parameters.Count != parms.Length) return 1;
  11448. for (int i = 0; i < parms.Length; i++)
  11449. {
  11450. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  11451. }
  11452. if (!(result.ToString() == str))
  11453. {
  11454. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  11455. return 1;
  11456. }
  11457. return 0;
  11458. }
  11459. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  11460. {
  11461. if (!(result.NodeType == et))
  11462. {
  11463. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  11464. return 1;
  11465. }
  11466. if (!(result.Type == type))
  11467. {
  11468. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  11469. return 1;
  11470. }
  11471. if (expr == null)
  11472. {
  11473. if (result.Expression != null) return 1;
  11474. }
  11475. else
  11476. {
  11477. if (!(result.Expression.Equals(expr))) return 1;
  11478. }
  11479. if (result.Arguments.Count != args.Length) return 1;
  11480. for (int i = 0; i < args.Length; i++)
  11481. {
  11482. if (!(result.Arguments[i].Equals(args[i])))
  11483. {
  11484. return 1;
  11485. }
  11486. }
  11487. if (result.ToString() != str)
  11488. {
  11489. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  11490. return 1;
  11491. }
  11492. return 0;
  11493. }
  11494. }
  11495. namespace Not
  11496. {
  11497. // Declaring user-defined types for testing
  11498. struct TC1
  11499. {
  11500. public static TC1 operator !(TC1 c)
  11501. {
  11502. return new TC1();
  11503. }
  11504. public static TC1 operator ~(TC1 c)
  11505. {
  11506. return new TC1();
  11507. }
  11508. }
  11509. struct TC2
  11510. {
  11511. public static TC2 operator ~(TC2 c)
  11512. {
  11513. return new TC2();
  11514. }
  11515. }
  11516. struct TC3
  11517. {
  11518. public static TC3 Meth1(TC3 c)
  11519. {
  11520. return new TC3();
  11521. }
  11522. }
  11523. }
  11524. }
  11525. }