using System;
using System.Reflection;
+using System.Reflection.Emit;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
}
[Test]
-#if NET_4_0
[ExpectedException (typeof (ArgumentException))]
-#else
- [ExpectedException (typeof (ArgumentNullException))]
-#endif
public void ArgInstanceNullForNonStaticMethod ()
{
Expression.Call (null, typeof (object).GetMethod ("ToString"));
[ExpectedException (typeof (ArgumentException))]
public void InstanceTypeDoesntMatchMethodDeclaringType ()
{
+#if MOBILE
+ // ensure that String.Intern won't be removed by the linker
+ string s = String.Intern (String.Empty);
+#endif
Expression.Call (Expression.Constant (1), typeof (string).GetMethod ("Intern"));
}
return 42;
}
+ [Test]
+ public void CallMethodOnDateTime ()
+ {
+ var left = Expression.Call (Expression.Constant (DateTime.Now), typeof(DateTime).GetMethod ("AddDays"), Expression.Constant (-5.0));
+ var right = Expression.Constant (DateTime.Today.AddDays (1));
+ var expr = Expression.GreaterThan (left, right);
+
+ var eq = Expression.Lambda<Func<bool>> (expr).Compile ();
+ Assert.IsFalse (eq ());
+ }
+
[Test]
[Category ("NotDotNet")] // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339351
[ExpectedException (typeof (ArgumentException))]
Assert.AreEqual ("foo42", lamda (42, "foo"));
}
- public static int Bang (Expression i)
+#if !MONOTOUCH
+ [Test]
+ public void CallDynamicMethod_ToString ()
{
- return (int) (i as ConstantExpression).Value;
+ // 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 ());
}
-#if !NET_4_0 // dlr bug 5875
+
[Test]
- public void CallMethodWithExpressionParameter ()
+ public void CallDynamicMethod_CompileInvoke ()
{
- var call = Expression.Call (GetType ().GetMethod ("Bang"), Expression.Constant (42));
- Assert.AreEqual (ExpressionType.Quote, call.Arguments [0].NodeType);
+ 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 l = Expression.Lambda<Func<int>> (call).Compile ();
+ var i = Expression.Parameter (typeof (int), "i");
+ var e = Expression.Call (m, i);
- Assert.AreEqual (42, l ());
+ var lambda = Expression.Lambda<Func<int, int>> (e, i).Compile ();
+ Assert.AreEqual (42, lambda (42));
}
#endif
+
+ public static int Bang (Expression i)
+ {
+ return (int) (i as ConstantExpression).Value;
+ }
static bool fout_called = false;
public static int FooOut (out int x)
}
[Test]
- [Category ("NotWorking")]
public void Connect290278 ()
{
// test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290278
[Test]
[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=319190
+ [Category ("NotWorkingInterpreter")]
public void Connect319190 ()
{
var lambda = Expression.Lambda<Func<bool>> (