internal TRunInfo Process() { TRunInfo runInfo = (TRunInfo)Activator.CreateInstance(typeof(TRunInfo)); ProcessContext <TRunInfo> context = new ProcessContext <TRunInfo>( runInfo, 0, _parser, _stages, _programArguments, _initialCommand, _globalOptions); Action <CommandBase <TRunInfo> > resetContextFunc = cmd => { context = context.RecreateForCommand(cmd); }; bool ended = false; while (_stages.Any()) { Stage <TRunInfo> current = _stages.Dequeue(); ProcessStageResult result = current.ProcessStage(context, resetContextFunc); switch (result) { case Continue _: break; case End _: ended = true; break; case null: default: throw new ProcessException( "Current stage processing returned an invalid result.", ProcessError.InvalidStageResult, context.CommandLevel); } if (ended) { break; } } return(runInfo); }