Skip to content

Commit

Permalink
Fix PowerShell Progress failing when piping from a variable containin…
Browse files Browse the repository at this point in the history
…g an Array/SZArrayEnumerator in .NET Core 3.1 (#136)
  • Loading branch information
lordmilko committed Mar 21, 2020
1 parent b425c16 commit 601d33a
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,18 @@ private static Pipeline GetCmdletPipelineInput(ICommandRuntime commandRuntime, I
else //Piping from a variable
{
var declaringType = enumerator.GetType().DeclaringType;
var enumeratorType = enumerator.GetType();

IEnumerable<object> list;

if (declaringType == typeof(Array)) //It's a SZArrayEnumerator (piping straight from a variable)
if (declaringType == typeof(Array) || enumeratorType.Name == "SZArrayEnumerator") //It's a SZArrayEnumerator (piping straight from a variable). In .NET Core 3.1 SZArrayEnumerator is no longer nested
list = ((object[]) enumerator.GetInternalField("_array"));
else if (declaringType == typeof(List<>)) //It's a List<T>.Enumerator (piping from $groups[0].Group)
list = enumerator.PSGetInternalField("_list", "list").ToIEnumerable();
else if (declaringType == typeof(ListBase<>))
list = enumerator.GetInternalField("list").ToIEnumerable();
else
throw new NotImplementedException($"Don't know how to extract the pipeline input from a '{enumerator.GetType()}' enumerator from type '{declaringType}'.");
throw new NotImplementedException($"Don't know how to extract the pipeline input from a '{enumeratorType}' enumerator from type '{declaringType}'.");

list = list.Select(o =>
{
Expand Down

0 comments on commit 601d33a

Please sign in to comment.