コード例 #1
0
        public void ExpressionSlimToExpressionConverter_Throw()
        {
            var ex = new Exception();

            var conv = new ExpressionSlimToExpressionConverter();

            {
                var t = ExpressionSlim.Throw(Expression.Constant(ex).ToExpressionSlim());
                var e = conv.Visit(t);

                Assert.AreEqual(ExpressionType.Throw, e.NodeType);

                var u = (UnaryExpression)e;
                Assert.AreEqual(typeof(void), u.Type);

                Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType);
                var c = (ConstantExpression)u.Operand;
                Assert.AreSame(ex, c.Value);
            }

            {
                var t = ExpressionSlim.Throw(Expression.Constant(ex).ToExpressionSlim(), typeof(int).ToTypeSlim());
                var e = conv.Visit(t);

                Assert.AreEqual(ExpressionType.Throw, e.NodeType);

                var u = (UnaryExpression)e;
                Assert.AreEqual(typeof(int), u.Type);

                Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType);
                var c = (ConstantExpression)u.Operand;
                Assert.AreSame(ex, c.Value);
            }

            {
                var t = ExpressionSlim.MakeUnary(ExpressionType.Throw, Expression.Constant(ex).ToExpressionSlim(), type: null);
                var e = conv.Visit(t);

                Assert.AreEqual(ExpressionType.Throw, e.NodeType);

                var u = (UnaryExpression)e;
                Assert.AreEqual(typeof(void), u.Type);

                Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType);
                var c = (ConstantExpression)u.Operand;
                Assert.AreSame(ex, c.Value);
            }
        }
コード例 #2
0
#pragma warning restore IDE0060 // Remove unused parameter

        protected static Expression ExpressionRoundtrip(Expression e)
        {
            var exprToSlim = new ExpressionToExpressionSlimConverter();
            var slimToExpr = new ExpressionSlimToExpressionConverter();

            return(slimToExpr.Visit(exprToSlim.Visit(e)));
        }
コード例 #3
0
        private static void AssertRoundtrip(Expression e)
        {
            var toSlim = new ExpressionToExpressionSlimConverter();
            var toLinq = new ExpressionSlimToExpressionConverter();
            var eqComp = new ExpressionEqualityComparer(() => new Comparator());

            var s = toSlim.Visit(e);
            var r = toLinq.Visit(s);

            Assert.IsTrue(eqComp.Equals(e, r), e.ToString());
        }
コード例 #4
0
 public override Expression Reduce(ExpressionSlim expression)
 {
     return(_reducer.Visit(expression));
 }