Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Use PSObject.Base method
  • Loading branch information
dlwyatt committed Oct 15, 2017
commit e4a1f762bb110606d52625c926061413baf060b5
20 changes: 2 additions & 18 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,22 +445,6 @@ internal static bool IsTypeEnumerable(Type type)
return (getEnumerable != LanguagePrimitives.ReturnNullEnumerable);
}

private static object GetBaseObject(object obj)
{
if (obj == null)
{
return null;
}

var psobj = obj as PSObject;
if (null != psobj)
{
obj = psobj.BaseObject;
}

return obj;
}

/// <summary>
/// Returns True if the language considers obj to be IEnumerable
/// </summary>
Expand All @@ -470,7 +454,7 @@ private static object GetBaseObject(object obj)
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "obj", Justification = "Since V1 code is already shipped, excluding this message.")]
public static bool IsObjectEnumerable(object obj)
{
return IsTypeEnumerable(GetBaseObject(obj)?.GetType());
return IsTypeEnumerable(PSObject.Base(obj)?.GetType());
}


Expand All @@ -483,7 +467,7 @@ public static bool IsObjectEnumerable(object obj)
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "obj", Justification = "Since V1 code is already shipped, excluding this message.")]
public static IEnumerable GetEnumerable(object obj)
{
obj = GetBaseObject(obj);
obj = PSObject.Base(obj);
if (obj == null) { return null; }
GetEnumerableDelegate getEnumerable = GetOrCalculateEnumerable(obj.GetType());
return getEnumerable(obj);

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 13, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not right. Before the change, the obj passed in getEnumerable is the base object if the original one is PSObject, but now it will be the PSObject in that case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, you're right. Fixing now.

Expand Down