public void TypeSlimDerivationVisitor_Block_Simple()
        {
            {
                var e = Expression.Block(Expression.Constant(42));
                RoundtripAndAssert(e);
            }

            {
                var p = Expression.Variable(typeof(int));
                var e =
                    Expression.Block(
                        new[] { p },
                        p
                        );
                RoundtripAndAssert(e);
            }

            {
                var p = Expression.Variable(typeof(int));
                var e =
                    Expression.Block(
                        new[] { p },
                        Expression.Constant("42"),
                        p
                        );
                RoundtripAndAssert(e);
            }

            {
                var p = Expression.Variable(typeof(int));
                var e =
                    Expression.Block(
                        new[] { p },
                        p,
                        Expression.Constant("42")
                        );
                RoundtripAndAssert(e);
            }

            {
                var e =
                    Expression.Block(
                        typeof(void),
                        Expression.Constant(42)
                        );
                RoundtripAndAssert(e);
            }

            {
                var e = new BlockExpressionSlim(variables: null, new[] { Expression.Constant(42).ToExpressionSlim() }.ToReadOnly(), typeof(string).ToTypeSlim());
                Assert.AreSame(Derive(e).ToType(), typeof(string));
            }

            {
                var e = new BlockExpressionSlim(variables: null, new[] { Expression.Constant(42).ToExpressionSlim() }.ToReadOnly(), type: null);
                Assert.AreSame(Derive(e).ToType(), typeof(int));
            }
        }
Beispiel #2
0
            protected internal override ExpressionSlim VisitBlock(BlockExpressionSlim node)
            {
                if (node.Variables.Count > 0)
                {
                    var frame = new HashSet <ParameterExpressionSlim>(node.Variables);
                    _environment.Push(frame);
                }

                var res = base.VisitBlock(node);

                if (node.Variables.Count > 0)
                {
                    _environment.Pop();
                }

                return(res);
            }