Exemple #1
0
        private Expression MakeAssignBlock(ParameterExpression variable, Expression value)
        {
            var node     = (BlockExpression)value;
            var newBlock = new ReadOnlyCollectionBuilder <Expression>(node.Expressions);

            Expression blockRhs = newBlock[newBlock.Count - 1];

            if (blockRhs.NodeType == ExpressionType.Label)
            {
                var             label       = (LabelExpression)blockRhs;
                GotoRewriteInfo curVariable = new GotoRewriteInfo(variable, Expression.Label(label.Target.Name + "_voided"));

                var rewriter = new GotoRewriter(this, curVariable, label.Target);
                for (int i = 0; i < newBlock.Count - 1; i++)
                {
                    newBlock[i] = rewriter.Visit(newBlock[i]);
                }

                newBlock[newBlock.Count - 1] = MakeAssignLabel(variable, curVariable, rewriter.Visit(label.DefaultValue));
            }
            else
            {
                newBlock[newBlock.Count - 1] = MakeAssign(variable, newBlock[newBlock.Count - 1]);
            }

            return(Expression.Block(node.Variables, newBlock));
        }
Exemple #2
0
        private Expression MakeAssignLabel(ParameterExpression variable, LabelExpression value)
        {
            GotoRewriteInfo curVariable = new GotoRewriteInfo(variable, Expression.Label(value.Target.Name + "_voided"));

            var defaultValue = new GotoRewriter(this, curVariable, value.Target).Visit(value.DefaultValue);

            return(MakeAssignLabel(variable, curVariable, defaultValue));
        }