Skip to content

Commit

Permalink
feat: [Ast].ByType (Fixes #639)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Nov 12, 2023
1 parent 308c967 commit 62e792f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Types/AST/get_ByType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
.SYNOPSIS
Gets PowerShell AST Nodes by type
.DESCRIPTION
Gets a dictionary of all nodes in a PowerShell AST beneath this point, grouped by type.
.EXAMPLE
{"hello world"}.Ast.ByType
#>
if (-not $this.'.ByType') {
$ByType = [Collections.Generic.Dictionary[Type,Collections.Generic.List[PSObject]]]::new()
foreach ($node in $this.FindAll({$true}, $true)) {
$nodeType = $node.GetType()

if (-not $ByType[$nodeType]) {
$ByType[$nodeType] = [Collections.Generic.List[PSObject]]::new()
}
$ByType[$nodeType].Add($node)
}
Add-Member -InputObject $this -MemberType NoteProperty -Name '.ByType' -Value $ByType -Force
}

$this.'.ByType'

0 comments on commit 62e792f

Please sign in to comment.