forked from ModuleBuild/ModuleBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ParentASTTypes.ps1
More file actions
52 lines (47 loc) · 1.44 KB
/
Copy pathGet-ParentASTTypes.ps1
File metadata and controls
52 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Get-ParentASTTypes {
<#
.SYNOPSIS
Retrieves all parent types of a given AST element.
.DESCRIPTION
.PARAMETER Code
Multiline or piped lines of code to process.
.EXAMPLE
Description
-----------
.NOTES
Author: Zachary Loeber
Site: http://www.the-little-things.net/
Requires: Powershell 3.0
Version History
1.0.0 - Initial release
#>
[CmdletBinding()]
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline=$true, HelpMessage='AST element to process.')]
$AST
)
# Pull in all the caller verbose,debug,info,warn and other preferences
if ($script:ThisModuleLoaded -eq $true) { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState }
$FunctionName = $MyInvocation.MyCommand.Name
Write-Verbose "$($FunctionName): Begin."
$ASTParents = @()
if ($AST.Parent -ne $null) {
$CurrentParent = $AST.Parent
$KeepProcessing = $true
}
else {
$KeepProcessing = $false
}
while ($KeepProcessing) {
$ASTParents += $CurrentParent.GetType().Name.ToString()
if ($CurrentParent.Parent -ne $null) {
$CurrentParent = $CurrentParent.Parent
$KeepProcessing = $true
}
else {
$KeepProcessing = $false
}
}
$ASTParents
Write-Verbose "$($FunctionName): End."
}