Skip to content

Commit 3939df7

Browse files
StartAutomatingStartAutomating
authored andcommitted
VariableExpressionAst.GetVariableType - Enabling InvokeMemberExpression (Fixes #490)
1 parent 0ffb352 commit 3939df7

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

PipeScript.types.ps1xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,11 +2564,19 @@ foreach ($parent in $this.GetLineage()) {
25642564
$y = 2
25652565
$x + $y
25662566
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.Left.GetVariableType()
2567+
# Should -Be ([int])
25672568
.EXAMPLE
25682569
{
25692570
$x = Get-Process
25702571
$x + $y
25712572
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.Left.GetVariableType()
2573+
# Should -Be ([Diagnostics.Process])
2574+
.EXAMPLE
2575+
{
2576+
$x = [type].name
2577+
$x
2578+
}.Ast.EndBlock.Statements[-1].PipelineElements[0].Expression.GetVariableType()
2579+
25722580
#>
25732581
if ($this.VariablePath.userPath -eq 'psBoundParmeters') {
25742582
return [Management.Automation.PSBoundParametersDictionary]
@@ -2610,7 +2618,7 @@ $isMultiAssignment =$closestAssignment.Left -is [Management.Automation.Language.
26102618

26112619
# If the left side is not multiple assignment, but the right side is an array
26122620
if (-not $isMultiAssignment -and
2613-
$closestAssignment.Right.Expression -is [Management.Automation.ArrayExpressionAst]) {
2621+
$closestAssignment.Right.Expression -is [Management.Automation.Language.ArrayExpressionAst]) {
26142622
# then the object is an array.
26152623
return [Object[]]
26162624
}
@@ -2634,7 +2642,24 @@ if ($closestAssignment.Right.Expression -is [Management.Automation.Language.Conv
26342642
}
26352643
}
26362644

2637-
2645+
if ($closestAssignment.Right.Expression -is [Management.Automation.Language.MemberExpressionAst]) {
2646+
$invokeMemberExpr = $closestAssignment.Right.Expression
2647+
$memberName = $invokeMemberExpr.Member.ToString()
2648+
if ($invokeMemberExpr.Expression.TypeName) {
2649+
$invokeType = $invokeMemberExpr.Expression.TypeName.GetReflectionType()
2650+
if ($invokeType) {
2651+
$potentialTypes = @(
2652+
foreach ($invokeableMember in $invokeType.GetMember($memberName, "Public, IgnoreCase,$(if ($invokeMemberExpr.Static) { 'Static'} else { 'Instance'})")) {
2653+
if ($invokeableMember.PropertyType) {
2654+
$invokeableMember.PropertyType
2655+
} elseif ($invokeableMember.ReturnType) {
2656+
$invokeableMember.ReturnType
2657+
}
2658+
})
2659+
return $potentialTypes | Select-Object -Unique
2660+
}
2661+
}
2662+
}
26382663

26392664

26402665
# The right side could be a pipeline

0 commit comments

Comments
 (0)