예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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()));
        }
예제 #4
0
 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));
 }
예제 #5
0
 protected override Expression ResolveExpression <T>(T expression, MemberInfo member, Func <T, Expression> visit)
 {
     return(FuncletExpression.Create(expression));
 }
예제 #6
0
 internal virtual Expression VisitFunclet(FuncletExpression f)
 {
     return(f);
 }