using System;
using System.Reflection;
+using System.Reflection.Emit;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
Assert.AreEqual ("foo42", lamda (42, "foo"));
}
+ [Test]
+ public void CallDynamicMethod_ToString ()
+ {
+ // Regression test for #49686
+ var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+ var ilg = m.GetILGenerator ();
+ ilg.Emit (OpCodes.Ldarg_0);
+ ilg.Emit (OpCodes.Ret);
+
+ var i = Expression.Parameter (typeof (int), "i");
+ var e = Expression.Call (m, i);
+
+ Assert.IsNotNull (e.ToString ());
+ }
+
+ [Test]
+ public void CallDynamicMethod_CompileInvoke ()
+ {
+ var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+ var ilg = m.GetILGenerator ();
+ ilg.Emit (OpCodes.Ldarg_0);
+ ilg.Emit (OpCodes.Ret);
+
+ var i = Expression.Parameter (typeof (int), "i");
+ var e = Expression.Call (m, i);
+
+ var lambda = Expression.Lambda<Func<int, int>> (e, i).Compile ();
+ Assert.AreEqual (42, lambda (42));
+ }
+
public static int Bang (Expression i)
{
return (int) (i as ConstantExpression).Value;