Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,32 @@ namespace Microsoft.PowerShell.Commands
[Cmdlet(VerbsCommunications.Write, "Output", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113427", RemotingCapability = RemotingCapability.None)]
public sealed class WriteOutputCommand : PSCmdlet
{
private PSObject[] _inputObjects = null;

/// <summary>
/// Holds the list of objects to be written.
/// </summary>
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromRemainingArguments = true)]
[AllowNull]
[AllowEmptyCollection]
public PSObject[] InputObject
{
get { return _inputObjects; }

set { _inputObjects = value; }
}
public PSObject InputObject { get; set; }

/// <summary>
/// Prevents Write-Output from unravelling collections passed to the InputObject parameter.
/// </summary>
[Parameter()]
public SwitchParameter NoEnumerate
{
get;
set;
}
[Parameter]
public SwitchParameter NoEnumerate { get; set; }

/// <summary>
/// This method implements the ProcessRecord method for Write-output command.
/// </summary>
protected override void ProcessRecord()
{
if (_inputObjects == null)
if (InputObject == null)
{
WriteObject(_inputObjects);
WriteObject(InputObject);
return;
}

bool enumerate = true;
if (NoEnumerate.IsPresent)
{
enumerate = false;
}

WriteObject(_inputObjects, enumerate);
WriteObject(InputObject, !NoEnumerate.IsPresent);
}
}
#endregion
Expand Down
8 changes: 4 additions & 4 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void WriteObject(object sendToPipeline, bool enumerateCollection)

#if CORECLR
// SecurityContext is not supported in CoreCLR
DoWriteObjects(sendToPipeline);
DoWriteEnumeratedObject(sendToPipeline);
Comment thread
iSazonov marked this conversation as resolved.
Outdated
#else
if (UseSecurityContextRun)
{
Expand Down Expand Up @@ -278,11 +278,11 @@ public void WriteObject(object sendToPipeline, bool enumerateCollection)
/// <exception cref="System.InvalidOperationException">
/// Not permitted at this time or from this thread
/// </exception>
private void DoWriteObjects(object sendToPipeline)
private void DoWriteEnumeratedObject(object sendToPipeline)
{
// NOTICE-2004/06/08-JonN 959638
ThrowIfWriteNotPermitted(true);
_WriteObjectsSkipAllowCheck(sendToPipeline);
_EnumerateAndWriteObjectSkipAllowCheck(sendToPipeline);
}
// Trust: public void WriteObject(object sendToPipeline, DataTrustCategory trustCategory); // enumerateCollection defaults to false
// Trust: public void WriteObject(object sendToPipeline, bool enumerateCollection, DataTrustCategory trustCategory);
Expand Down Expand Up @@ -2591,7 +2591,7 @@ internal void _WriteObjectSkipAllowCheck(object sendToPipeline)
/// The Cmdlet should generally just allow PipelineStoppedException
/// to percolate up to the caller of ProcessRecord etc.
/// </exception>
internal void _WriteObjectsSkipAllowCheck(object sendToPipeline)
internal void _EnumerateAndWriteObjectSkipAllowCheck(object sendToPipeline)
{
IEnumerable enumerable = LanguagePrimitives.GetEnumerable(sendToPipeline);
if (enumerable == null)
Expand Down