//
// Authors:
// Miguel de Icaza (miguel@novell.com)
+// Jb Evain (jbevain@novell.com)
+//
using System;
using System.Reflection;
Expression.Lambda (typeof (delegate_object_object), Expression.Constant ("foo"), new ParameterExpression [1] {p});
}
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void NullParameter ()
+ {
+ Expression.Lambda<Func<int, int>> (Expression.Constant (1), new ParameterExpression [] { null });
+ }
+
[Test]
public void Assignability ()
{
}
[Test]
- public void LambdaReturningExpression ()
+ [Category ("NotWorking")]
+ public void LambdaPassedAsDelegateUsingParentParameter ()
{
- var l = Expression.Lambda<Func<Expression>> (Expression.Constant (42));
- Assert.AreEqual (ExpressionType.Quote, l.Body.NodeType);
+ var a = Expression.Parameter (typeof (int), "a");
+ var b = Expression.Parameter (typeof (int), "b");
+
+ var l = Expression.Lambda<Func<int, int>> (
+ Expression.Call (
+ this.GetType ().GetMethod ("CallDelegate"),
+ Expression.Lambda<Func<int, int>> (
+ Expression.Multiply (a, b), b)),
+ a).Compile ();
- var quoter = l.Compile ();
+ Assert.AreEqual (84, l (2));
+ }
- var q = quoter ();
+ public static int CallFunc (Func<int, int> e, int i)
+ {
+ return e (i);
+ }
- Assert.AreEqual (ExpressionType.Constant, q.NodeType);
+ [Test]
+ public void NestedParentParameterUse ()
+ {
+ var a = Expression.Parameter (typeof (int), null);
+ var b = Expression.Parameter (typeof (int), null);
+ var c = Expression.Parameter (typeof (int), null);
+ var d = Expression.Parameter (typeof (int), null);
+
+ var l = Expression.Lambda<Func<int, int>> (
+ Expression.Call (
+ this.GetType ().GetMethod ("CallFunc"),
+ Expression.Lambda<Func<int, int>> (
+ Expression.Call (
+ this.GetType ().GetMethod ("CallFunc"),
+ Expression.Lambda<Func<int, int>> (
+ Expression.Call (
+ this.GetType ().GetMethod ("CallFunc"),
+ Expression.Lambda<Func<int, int>> (
+ Expression.Add (c, d),
+ d),
+ Expression.Add (b, c)),
+ c),
+ Expression.Add (a, b)),
+ b),
+ a),
+ a).Compile ();
+
+ Assert.AreEqual (5, l (1));
}
}
}