Skip to content

Commit d6d13c8

Browse files
StartAutomatingStartAutomating
authored andcommitted
enhancement: Extending Microsoft.CodeAnalysis.SyntaxTree (Fixes #549)
1 parent b5b0fbb commit d6d13c8

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
System.Management.Automation.Language.VariableExpressionAst.GetVariableType()
2+
-----------------------------------------------------------------------------
3+
4+
5+
6+
7+
### Synopsis
8+
Gets a Variable's Likely Type
9+
10+
11+
12+
---
13+
14+
15+
### Description
16+
17+
Determines the type of a variable.
18+
19+
This looks for the closest assignment statement and uses this to determine what type the variable is likely to be.
20+
21+
22+
23+
---
24+
25+
26+
### Examples
27+
> EXAMPLE 1
28+
29+
```PowerShell
30+
{
31+
[int]$x = 1
32+
$y = 2
33+
$x + $y
34+
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.Left.GetVariableType()
35+
# Should -Be ([int])
36+
```
37+
> EXAMPLE 2
38+
39+
```PowerShell
40+
{
41+
$x = Get-Process
42+
$x + $y
43+
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.Left.GetVariableType()
44+
# Should -Be ([Diagnostics.Process])
45+
```
46+
> EXAMPLE 3
47+
48+
```PowerShell
49+
{
50+
$x = [type].name
51+
$x
52+
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.GetVariableType()
53+
```
54+
55+
56+
---
57+
58+
59+
### Notes
60+
Subject to revision and improvement. While this covers many potential scenarios, it does not always
61+
62+
63+
64+
---

0 commit comments

Comments
 (0)