Skip to content

Commit

Permalink
feat: [SyntaxNode/Tree].ByType (Fixes #644)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Nov 12, 2023
1 parent 1d52282 commit ce0910e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Types/Microsoft.CodeAnalysis/SyntaxNode/get_ByType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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'
11 changes: 11 additions & 0 deletions Types/Microsoft.CodeAnalysis/SyntaxTree/get_ByType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<#
.SYNOPSIS
Gets CSharp AST Nodes by type
.DESCRIPTION
Gets a dictionary of all nodes in a CSharp AST beneath this point, grouped by type.
.EXAMPLE
(Parse-CSharp '"Hello World";').ByType
#>


$this.Root.ByType

0 comments on commit ce0910e

Please sign in to comment.