diff --git a/src/System.Management.Automation/engine/PSClassSearcher.cs b/src/System.Management.Automation/engine/PSClassSearcher.cs index 970dc68ccb..e8e09931a6 100644 --- a/src/System.Management.Automation/engine/PSClassSearcher.cs +++ b/src/System.Management.Automation/engine/PSClassSearcher.cs @@ -296,8 +296,7 @@ namespace System.Management.Automation foreach (var member in statement.Members) { - PropertyMemberAst propAst = member as PropertyMemberAst; - if (propAst != null) + if (member is PropertyMemberAst propAst && !propAst.PropertyAttributes.HasFlag(PropertyAttributes.Hidden)) { Dbg.Assert(propAst.Name != null, "PropName cannot be null"); Dbg.Assert(propAst.PropertyType != null, "PropertyType cannot be null"); diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 58722ecf52..dbb42f02d0 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -295,6 +295,14 @@ Describe "Get-Help should find pattern help files" -Tags "CI" { Remove-Item $helpFilePath2 -Force -ErrorAction SilentlyContinue } + BeforeEach { + $currentPSModulePath = $env:PSModulePath + } + + AfterEach { + $env:PSModulePath = $currentPSModulePath + } + $testcases = @( @{command = {Get-Help about_testCas?1}; testname = "test ? pattern"; result = "about_test1"} @{command = {Get-Help about_testCase.?}; testname = "test ? pattern with dot"; result = "about_test2"} @@ -309,6 +317,22 @@ Describe "Get-Help should find pattern help files" -Tags "CI" { ) $command.Invoke() | Should -Be $result } + + It "Get-Help should fail expectedly searching for class help with hidden members" { + $testModule = @' + class foo + { + hidden static $monthNames = @('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec') + } +'@ + $modulesFolder = Join-Path $TestDrive "Modules" + $modulePath = Join-Path $modulesFolder "TestModule" + New-Item -ItemType Directory -Path $modulePath -Force > $null + Set-Content -Path (Join-Path $modulePath "TestModule.psm1") -Value $testModule + $env:PSModulePath += [System.IO.Path]::PathSeparator + $modulesFolder + + { Get-Help -Category Class -Name foo -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand" + } } Describe "Get-Help should find pattern alias" -Tags "CI" {