We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 308c967 commit 62e792fCopy full SHA for 62e792f
Types/AST/get_ByType.ps1
@@ -0,0 +1,22 @@
1
+<#
2
+.SYNOPSIS
3
+ Gets PowerShell AST Nodes by type
4
+.DESCRIPTION
5
+ Gets a dictionary of all nodes in a PowerShell AST beneath this point, grouped by type.
6
+.EXAMPLE
7
+ {"hello world"}.Ast.ByType
8
+#>
9
+if (-not $this.'.ByType') {
10
+ $ByType = [Collections.Generic.Dictionary[Type,Collections.Generic.List[PSObject]]]::new()
11
+ foreach ($node in $this.FindAll({$true}, $true)) {
12
+ $nodeType = $node.GetType()
13
+
14
+ if (-not $ByType[$nodeType]) {
15
+ $ByType[$nodeType] = [Collections.Generic.List[PSObject]]::new()
16
+ }
17
+ $ByType[$nodeType].Add($node)
18
19
+ Add-Member -InputObject $this -MemberType NoteProperty -Name '.ByType' -Value $ByType -Force
20
+}
21
22
+$this.'.ByType'
0 commit comments