public void FuncletExpression_Basics3() { var c = Expression.Constant("bar"); var f = FuncletExpression.Create <string>(c); var r = new NoOpVisitor().Visit(f); var eq = new ExpressionEqualityComparator(); Assert.IsTrue(eq.Equals(Expression.Constant("bar"), r)); }
public void FuncletExpression_Basics2() { var a = new Foo(); var c = Expression.Constant(a); var f = FuncletExpression.Create(c); a.x = 42; Assert.AreEqual(42, f.Reduce().Evaluate <Foo>().x); a.x = 43; Assert.AreEqual(43, f.ReduceAndCheck().Evaluate <Foo>().x); a.x = 44; Assert.AreEqual(44, f.ReduceExtensions().Evaluate <Foo>().x); }
public void FuncletExpression_Basics1() { var c = Expression.Constant(42); var f = FuncletExpression.Create(c); Assert.IsTrue(f.CanReduce); Assert.AreEqual(ExpressionType.Extension, f.NodeType); Assert.AreEqual(typeof(int), f.Type); Assert.AreEqual("Eval(42)", f.ToString()); Assert.AreEqual(42, f.Reduce().Evaluate <int>()); Assert.AreEqual(42, f.ReduceAndCheck().Evaluate <int>()); Assert.AreEqual(42, f.ReduceExtensions().Evaluate <int>()); var eq = new ExpressionEqualityComparer(); Assert.IsTrue(eq.Equals(c, f.Reduce())); Assert.IsTrue(eq.Equals(c, f.ReduceAndCheck())); Assert.IsTrue(eq.Equals(c, f.ReduceExtensions())); }
public void FuncletExpression_ArgumentChecking() { AssertEx.ThrowsException <ArgumentNullException>(() => FuncletExpression.Create(expression: null), ex => Assert.AreEqual("expression", ex.ParamName)); AssertEx.ThrowsException <ArgumentNullException>(() => FuncletExpression.Create <int>(expression: null), ex => Assert.AreEqual("expression", ex.ParamName)); }
protected override Expression ResolveExpression <T>(T expression, MemberInfo member, Func <T, Expression> visit) { return(FuncletExpression.Create(expression)); }