Assert.AreEqual (ExpressionType.AndAlso, expr.NodeType, "AndAlso#01");
Assert.AreEqual (typeof (bool), expr.Type, "AndAlso#02");
Assert.IsNull (expr.Method, "AndAlso#03");
+#if !NET_4_0
Assert.AreEqual ("(True && False)", expr.ToString(), "AndAlso#04");
+#endif
}
[Test]
Assert.AreEqual (typeof (OpClass), expr.Type, "AndAlso#06");
Assert.AreEqual (mi, expr.Method, "AndAlso#07");
Assert.AreEqual ("op_BitwiseAnd", expr.Method.Name, "AndAlso#08");
+#if !NET_4_0
Assert.AreEqual ("(value(MonoTests.System.Linq.Expressions.OpClass) && value(MonoTests.System.Linq.Expressions.OpClass))",
expr.ToString(), "AndAlso#09");
+#endif
}
[Test]
}
[Test]
- [Category ("NotWorking")]
+ public void UserDefinedAndAlsoShortCircuit ()
+ {
+ var i = Expression.Parameter (typeof (Item<Slot>), "i");
+ var and = Expression.Lambda<Func<Item<Slot>, Slot>> (
+ Expression.AndAlso (
+ Expression.Property (i, "Left"),
+ Expression.Property (i, "Right")), i).Compile ();
+
+ var item = new Item<Slot> (new Slot (0), new Slot (1));
+ Assert.AreEqual (new Slot (0), and (item));
+ Assert.IsTrue (item.LeftCalled);
+ Assert.IsFalse (item.RightCalled);
+ }
+
+ [Test]
+ [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=350228
+ public void UserDefinedLiftedAndAlsoShortCircuit ()
+ {
+ var i = Expression.Parameter (typeof (Item<Slot?>), "i");
+ var and = Expression.Lambda<Func<Item<Slot?>, Slot?>> (
+ Expression.AndAlso (
+ Expression.Property (i, "Left"),
+ Expression.Property (i, "Right")), i).Compile ();
+
+ var item = new Item<Slot?> (null, new Slot (1));
+ Assert.AreEqual ((Slot?) null, and (item));
+ Assert.IsTrue (item.LeftCalled);
+ Assert.IsFalse (item.RightCalled);
+ }
+
+ [Test]
public void UserDefinedAndAlsoLiftedToNull ()
{
var l = Expression.Parameter (typeof (Slot?), "l");
Expression.AndAlso (l, r, method);
}
+
+ class A {
+ public static bool operator true (A x)
+ {
+ return true;
+ }
+
+ public static bool operator false (A x)
+ {
+ return false;
+ }
+ }
+
+ class B : A {
+ public static B operator & (B x, B y)
+ {
+ return new B ();
+ }
+
+ public static bool op_True<T> (B x)
+ {
+ return true;
+ }
+
+ public static bool op_False (B x)
+ {
+ return false;
+ }
+ }
+
+ [Test] // from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=350487
+ public void Connect350487 ()
+ {
+ var p = Expression.Parameter (typeof (B), "b");
+ var l = Expression.Lambda<Func<B, A>> (
+ Expression.AndAlso (p, p), p).Compile ();
+
+ Assert.IsNotNull (l (null));
+ }
}
}