File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
docs/System/Management/Automation/Language/VariableExpressionAst Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
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
+ ---
You can’t perform that action at this time.
0 commit comments