Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/System.Management.Automation/engine/CommandDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,6 @@ private static string BuildPSSnapInDisplayName(PSSnapInSpecification PSSnapin)
/// <param name="sessionState">The session state the commandInfo should be run in.</param>
/// <returns>
/// </returns>
/// <exception cref="CommandNotFoundException">
/// If the command, <paramref name="commandName"/>, could not be found.
/// </exception>
/// <exception cref="System.Management.Automation.PSSecurityException">
/// If the security manager is preventing the command from running.
/// </exception>
Expand Down Expand Up @@ -575,7 +572,15 @@ internal CommandProcessorBase LookupCommandProcessor(CommandInfo commandInfo,
processor = new NativeCommandProcessor((ApplicationInfo)commandInfo, Context);
break;
case CommandTypes.Cmdlet:
processor = new CommandProcessor((CmdletInfo)commandInfo, Context);
var cmdletInfo = (CmdletInfo)commandInfo;
if (cmdletInfo.ImplementingType == typeof(ForEachObjectCommand))
{
processor = new SimpleForEachObjectCommandProcessor(cmdletInfo, Context);
}
else
{
processor = new CommandProcessor(cmdletInfo, Context);
}
break;
case CommandTypes.ExternalScript:
ExternalScriptInfo scriptInfo = (ExternalScriptInfo)commandInfo;
Expand Down
31 changes: 30 additions & 1 deletion src/System.Management.Automation/engine/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ internal CommandProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext
Init(scriptCommandInfo);
}

protected CommandProcessor(CmdletInfo cmdletInfo, ExecutionContext context, ForEachObjectCommand instance)
: base(cmdletInfo)
{
this._context = context;
this.Command = instance;
this.CommandScope = Context.EngineSessionState.CurrentScope;

InitCommon();
}

#endregion ctor

#region internal members
Expand Down Expand Up @@ -663,7 +673,12 @@ private bool ProcessInputPipelineObject(object inputObject)

Command.CurrentPipelineObject = inputToOperateOn;

return this.CmdletParameterBinderController.BindPipelineParameters(inputToOperateOn);
return this.BindPipelineParameters(inputToOperateOn);
}

protected virtual bool BindPipelineParameters(PSObject inputObject)
{
return this.CmdletParameterBinderController.BindPipelineParameters(inputObject);
}

private static readonly ConcurrentDictionary<Type, Func<Cmdlet>> s_constructInstanceCache;
Expand Down Expand Up @@ -868,5 +883,19 @@ internal override bool IsHelpRequested(out string helpTarget, out HelpCategory h

#endregion helper_methods
}

internal class SimpleForEachObjectCommandProcessor : CommandProcessor
{
internal SimpleForEachObjectCommandProcessor(CmdletInfo cmdletInfo, ExecutionContext context)
: base(cmdletInfo, context, new ForEachObjectCommand())
{
}

protected override bool BindPipelineParameters(PSObject inputObject)
{
((ForEachObjectCommand)this.Command).InputObject = inputObject;
return true;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ internal abstract class CommandProcessorBase : IDisposable
{
#region ctor

/// <summary>
/// Default constructor.
/// </summary>
internal CommandProcessorBase()
{
}

/// <summary>
/// Initializes the base command processor class with the command metadata.
/// </summary>
Expand Down