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"));
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void CallMethodOnStruct ()
{
var param = Expression.Parameter (typeof (EineStrukt), "s");
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))]
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void CallStaticMethodWithRefParameter ()
{
var p = Expression.Parameter (typeof (int), "i");
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void CallStaticMethodWithRefParameterAndOtherParameter ()
{
var i = Expression.Parameter (typeof (int), "i");
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 ("NotWorkingInterpreter")]
public void Connect282729 ()
{
// test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=282729
}
[Test]
- [Category ("NotWorking")]
- [Category ("NotWorkingInterpreter")]
public void Connect290278 ()
{
// test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290278
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void Connect297597 ()
{
// test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=297597
[Test]
[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=319190
+ [Category ("NotWorkingInterpreter")]
public void Connect319190 ()
{
var lambda = Expression.Lambda<Func<bool>> (
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void Connect282702 ()
{
var lambda = Expression.Lambda<Func<Func<int>>> (
}
[Test]
- [Category ("NotWorkingInterpreter")]
public void CallNullableGetValueOrDefault () // #568989
{
var value = Expression.Parameter (typeof (int?), "value");