private CommandProcessorBase CreateCommandProcessor( out int index, ExecutionContext context) { index = 0; CommandProcessorBase commandProcessorBase = (CommandProcessorBase)null; if (this._expression != null) { return((CommandProcessorBase) new ScriptCommandProcessor(ScriptBlock.CreateSynthesized(this._expression, this.NodeToken), context, false)); } bool createScope; SessionStateInternal commandSessionState; bool forceSessionState; object commandName = this.GetCommandName(out createScope, out index, out commandSessionState, out forceSessionState, context); switch (commandName) { case ScriptBlock scriptblock: commandProcessorBase = CommandDiscovery.CreateCommandProcessorForScript(scriptblock, context, createScope); if (commandProcessorBase.CommandSessionState == null || forceSessionState) { commandProcessorBase.CommandSessionState = commandSessionState; break; } break; case CommandInfo commandInfo: commandProcessorBase = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.currentScope.ScopeOrigin, new bool?(false)); break; case string stringParser: label_7: if (string.IsNullOrEmpty(stringParser)) { throw InterpreterError.NewInterpreterException(commandName, typeof(RuntimeException), (Token)this._elements[0], "BadExpression", (object)((Token)this._elements[0]).TokenText); } try { if (commandSessionState != context.EngineSessionState) { SessionStateInternal engineSessionState = context.EngineSessionState; try { context.EngineSessionState = commandSessionState; commandProcessorBase = context.CreateCommand(stringParser); break; } finally { context.EngineSessionState = engineSessionState; } } else { commandProcessorBase = context.CreateCommand(stringParser); break; } } catch (ParseException ex) { throw; } catch (RuntimeException ex) { if (ex.ErrorRecord.InvocationInfo == null) { ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, (Token)this._elements[0], context)); } throw; } default: stringParser = PSObject.ToStringParser(context, commandName); goto label_7; } if (commandProcessorBase.CommandSessionState == null || forceSessionState) { commandProcessorBase.CommandSessionState = commandSessionState; } InternalCommand command = commandProcessorBase.Command; command.MyInvocation.ScriptToken = (Token)this._elements[0]; if (context.IsStrictVersion(2) && this._elements.Count == index + 1 && (this._elements[index - 1] is Token && this._elements[index] is ArrayLiteralNode)) { Token element = (Token)this._elements[index - 1]; if (element.Script[element.End] == '(') { throw InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), (Token)this._elements[index - 1], "StrictModeFunctionCallWithParens"); } } if (createScope) { switch (command) { case ScriptCommand _: case PSScriptCmdlet _: commandProcessorBase.UseLocalScope = true; commandProcessorBase.CommandScope = commandProcessorBase.CommandSessionState == null?context.EngineSessionState.NewScope(commandProcessorBase.FromScriptFile) : commandProcessorBase.CommandSessionState.NewScope(commandProcessorBase.FromScriptFile); goto label_27; } } commandProcessorBase.UseLocalScope = false; commandProcessorBase.CommandScope = commandProcessorBase.CommandSessionState.CurrentScope; label_27: commandProcessorBase.Command.CallingToken = (Token)this._elements[0]; return(commandProcessorBase); }