@@ -30,23 +30,43 @@ function Parse.CSharp {
30
30
[PSObject ]
31
31
$Source
32
32
)
33
- begin {
33
+ begin {
34
34
if (-not (' Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree' -as [type ])) {
35
35
Add-Type - AssemblyName Microsoft.CodeAnalysis.CSharp
36
- }
36
+ }
37
+ $accumulate = [Collections.Queue ]::new()
37
38
}
38
39
process {
40
+ $accumulate.Enqueue ([Ordered ]@ {psParameterSet = $psCmdlet.ParameterSetName } + $PSBoundParameters )
41
+ }
42
+ end {
43
+ $count = 0
44
+ $total = $accumulate.Count -as [double ]
45
+ if (-not $script :LastProgressID ) { $script :LastProgressID = 1 }
46
+ $script :LastProgressID ++
39
47
if (-not (' Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree' -as [type ])) {
40
48
return
41
49
}
42
- if ($Source -is [string ]) {
43
- [Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree ]::ParseText($Source )
44
- }
45
- elseif ($Source -is [IO.FileInfo ]) {
46
- if ($Source.Extension -in ' .cs' , ' .csx' ) {
47
- [Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree ]::ParseText([IO.File ]::ReadAllText($Source ), $null , $Source.Fullname )
50
+ while ($accumulate.Count ) {
51
+ $dequeue = $accumulate.Dequeue ()
52
+ if ($total -gt 1 ) {
53
+ Write-Progress " Parsing PowerShell" " " - Id $script :LastProgressID - PercentComplete $ (
54
+ $count ++
55
+ [Math ]::Min($count / $total , 1 ) * 100
56
+ )
57
+ }
58
+ foreach ($kv in $dequeue.GetEnumerator ()) {
59
+ $ExecutionContext.SessionState.PSVariable.Set ($kv.Key , $kv.Value )
60
+ }
61
+ if ($Source -is [string ]) {
62
+ [Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree ]::ParseText($Source )
63
+ }
64
+ elseif ($Source -is [IO.FileInfo ]) {
65
+ if ($Source.Extension -in ' .cs' , ' .csx' ) {
66
+ [Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree ]::ParseText([IO.File ]::ReadAllText($Source ), $null , $Source.Fullname )
67
+ }
68
+
48
69
}
49
-
50
70
}
51
71
}
52
72
}
0 commit comments