Skip to content
Merged
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 @@ -427,7 +427,29 @@ private static bool TryGetRepresentativeTypeNameFromValue(object value, out PSTy
value = PSObject.Base(value);
if (value != null)
{
type = new PSTypeName(value.GetType());
var typeObject = value.GetType();

if (typeObject.FullName.Equals("System.Management.Automation.PSObject", StringComparison.Ordinal))
{
var psobjectPropertyList = new List<PSMemberNameAndType>();
foreach (var property in ((PSObject)value).Properties)
{
if (property.IsHidden)
{
continue;
}

var propertyTypeName = new PSTypeName(property.TypeNameOfValue);
psobjectPropertyList.Add(new PSMemberNameAndType(property.Name, propertyTypeName, property.Value));
}

type = PSSyntheticTypeName.Create(typeObject, psobjectPropertyList);
}
else
{
type = new PSTypeName(typeObject);
}

return true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,13 @@ ConstructorTestClass(int i, bool b)
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Length'
}

It 'Should complete psobject members for variable' {
$TestVar = Get-Command Get-Command | Select-Object CommandType
$res = TabExpansion2 -inputScript '$TestVar | ForEach-Object {$_.commandtype'
$res | Should -HaveCount 1
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'CommandType'
}

Context "Format cmdlet's View paramter completion" {
BeforeAll {
$viewDefinition = @'
Expand Down