Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,37 @@ private string ProcessObject(object o)
{
if (o != null)
{
if (o is string s)
switch (o)
{
// strings are IEnumerable, so we special case them
if (s.Length > 0)
{
return s;
}
}
else if (o is XmlNode xmlNode)
{
return xmlNode.Name;
}
else if (o is IEnumerable enumerable)
{
// unroll enumerables, including arrays.

bool printSeparator = false;
StringBuilder result = new();

foreach (object element in enumerable)
{
if (printSeparator && Separator != null)
case string s:
// strings are IEnumerable, so we special case them
if (s.Length > 0)
{
result.Append(Separator.ToString());
return s;
}
break;
case XmlNode xmlNode:
return xmlNode.Name;
case IDictionary dictionary:
return dictionary.ToString();
case IEnumerable enumerable:
bool printSeparator = false;
StringBuilder result = new();

foreach (object element in enumerable)
{
if (printSeparator && Separator != null)
{
result.Append(Separator.ToString());
}

result.Append(ProcessObject(element));
printSeparator = true;
}

return result.ToString();
}
else
{
s = o.ToString();
result.Append(ProcessObject(element));
printSeparator = true;
}

if (s.Length > 0)
{
return s;
}
return result.ToString();
default:
return o.ToString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Describe "Write-Host with TestHostCS" -Tags "CI" {
@{ Name = '-NoNewline:$true and colors'; Command = "Write-Host a,b -NoNewline:`$true -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NoNewLine", "White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@{ Name = '-NoNewline:$false and colors'; Command = "Write-Host a,b -NoNewline:`$false -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NewLine","White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@{ Name = 'XMLElement'; Command = "Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
@{ Name = 'XMLDocument'; Command = "Write-Host ([system.xml.xmldocument] '<OhElement>Where art thou?</OhElement>').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a duplicate of this one.

@{ Name = 'XMLDocument'; Command = "Write-Host ([system.xml.xmldocument] '<OhElement>Where art thou?</OhElement>').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
@{ Name = 'IDictionary'; Command = "Write-Host @{Key1='Value1';Key2='Value2'}"; returnCount = 1; returnValue = @("White:Black:System.Collections.Hashtable:NewLine"); returnInfo = @("System.Collections.Hashtable") }
)

}
Expand Down
Loading