System.Management.Pash.Implementation.ExecutionVisitor.VisitStatement C# (CSharp) Method

VisitStatement() private method

private VisitStatement ( System.Management.Automation.Language.StatementAst statementAst ) : AstVisitAction
statementAst System.Management.Automation.Language.StatementAst
return AstVisitAction
        private AstVisitAction VisitStatement(StatementAst statementAst)
        {
            // We execute this in a subcontext, because single enumerable results are
            // evaluated and its values are written to pipeline (i.e. ". {1,2,3}" writes
            // all three values to pipeline
            // therefore we have to catch exceptions for now to read and write
            // the subVisitors' output stream, so that already written results appear
            // also in this OutputStream
            var subVisitor = this.CloneSub(false);
            subVisitor._pipelineCommandRuntime.ErrorStream.Redirect(_pipelineCommandRuntime.ErrorStream);
            try
            {
                statementAst.Visit(subVisitor);
            }
            finally
            {
                var result = subVisitor._pipelineCommandRuntime.OutputStream.Read();
                if (result.Count == 1)
                {
                    // this is the actual thing of this whole work: enumerate a single value!
                    _pipelineCommandRuntime.WriteObject(result.Single(), true);
                }
                else if (result.Count > 1)
                {
                    _pipelineCommandRuntime.WriteObject(result, true);
                }
            }
            return AstVisitAction.SkipChildren;
        }
ExecutionVisitor