private BlockExpression Deserialize(ParsedBlockExpression parsedExpression)
        {
            if (parsedExpression == null)
            {
                throw new ArgumentNullException(nameof(parsedExpression));
            }

            IEnumerable <Expression>          expressions = parsedExpression.Expressions.Select(Deserialize).Concat(new[] { Deserialize(parsedExpression.Result), }).ToArray();
            IEnumerable <ParameterExpression> variables   = parsedExpression.Variables.Select(Deserialize).ToArray();
            List <Expression> finalExpressions            = expressions.ToList();

            foreach (ParameterExpression variable in variables)
            {
                for (int i = 0; i < finalExpressions.Count; i++)
                {
                    ParameterReplacementVisitor visitorExpression = new ParameterReplacementVisitor(variable);
                    finalExpressions[i] = visitorExpression.Visit(finalExpressions[i]);
                }
            }

            return(Expression.Block(
                       parsedExpression.Type == null ? null : Deserialize(parsedExpression.Type),
                       variables,
                       finalExpressions));
        }
        private CatchBlock Deserialize(ParsedCatchBlock parsedCatchBlock)
        {
            if (parsedCatchBlock == null)
            {
                throw new ArgumentNullException(nameof(parsedCatchBlock));
            }

            Expression                  body              = parsedCatchBlock.Body == null ? null : Deserialize(parsedCatchBlock.Body);
            ParameterExpression         variable          = parsedCatchBlock.Variable == null ? null : Deserialize(parsedCatchBlock.Variable);
            ParameterReplacementVisitor visitorExpression = new ParameterReplacementVisitor(variable);
            Expression                  finalBody         = visitorExpression.Visit(body);

            return(Expression.MakeCatchBlock(
                       parsedCatchBlock.Type == null ? null : Deserialize(parsedCatchBlock.Type),
                       variable,
                       finalBody,
                       parsedCatchBlock.Filter == null ? null : Deserialize(parsedCatchBlock.Filter)));
        }
        private LambdaExpression Deserialize(ParsedLambdaExpression parsedExpression)
        {
            if (parsedExpression == null)
            {
                throw new ArgumentNullException(nameof(parsedExpression));
            }

            Expression body = parsedExpression.Body == null ? null : Deserialize(parsedExpression.Body);
            IEnumerable <ParameterExpression> parameters = parsedExpression.Parameters.Select(Deserialize).ToArray();
            Expression finalBody = body;

            foreach (ParameterExpression parameter in parameters)
            {
                ParameterReplacementVisitor visitorBody = new ParameterReplacementVisitor(parameter);
                finalBody = visitorBody.Visit(finalBody);
            }

            return(Expression.Lambda(
                       finalBody,
                       parsedExpression.Name,
                       parsedExpression.TailCall,
                       parameters));
        }