Skip to content

Commit 16c83bc

Browse files
author
James Brundage
committed
Updating ParameterAST Type Definitions (Fixes #305)
1 parent 5212d6f commit 16c83bc

File tree

8 files changed

+113
-0
lines changed

8 files changed

+113
-0
lines changed

Types/ParameterAST/Alias.psd1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@{
2+
FriendlyName = "DisplayName"
3+
ValueFromPipelineByPropertyName = "ByPropertyName"
4+
VBN = "ByPropertyName"
5+
VFPBN = "ByPropertyName"
6+
ValueByName = "ByPropertyName"
7+
VFP = "FromPipeline"
8+
ValueFromPipeline = "FromPipeline"
9+
ValueFromRemainingArguments = "FromUnbound"
10+
ValueFromRemaining = "FromUnbound"
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
foreach ($attr in $this.Attributes) {
2+
$reflectedType = $attr.TypeName.GetReflectionType()
3+
if ($reflectedType -ne [Management.Automation.ParameterAttribute]) {
4+
continue
5+
}
6+
foreach ($namedArgument in $attr.NamedArguments) {
7+
if ($namedArgument.ArgumentName -ne 'ValueFromPipelineByPropertyName') {
8+
continue
9+
}
10+
if ($namedArgument.Argument -and $namedArgument.Argument.Value) {
11+
return $true
12+
} elseif (-not $namedArgument.Argument) {
13+
return $true
14+
}
15+
}
16+
}
17+
18+
return $false

Types/ParameterAST/get_DisplayName.ps1

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
foreach ($attr in $this.Attributes) {
2+
$reflectedType = $attr.TypeName.GetReflectionType()
3+
if ($reflectedType -ne [Management.Automation.ParameterAttribute]) {
4+
continue
5+
}
6+
foreach ($namedArgument in $attr.NamedArguments) {
7+
if ($namedArgument.ArgumentName -ne 'ValueFromPipeline') {
8+
continue
9+
}
10+
if ($namedArgument.Argument -and $namedArgument.Argument.Value) {
11+
return $true
12+
} elseif (-not $namedArgument.Argument) {
13+
return $true
14+
}
15+
}
16+
}
17+
18+
return $false

Types/ParameterAST/get_FromUnbound.ps1

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$metadata = [Ordered]@{}
2+
3+
foreach ($attr in $this.Attributes) {
4+
$reflectedType = $attr.TypeName.GetReflectionType()
5+
if ($reflectedType -ne [Reflection.AssemblyMetadataAttribute]) {
6+
continue
7+
}
8+
$key, $value =
9+
foreach ($positionalParameter in $attr.PositionalArguments) {
10+
$positionalParameter.Value
11+
}
12+
13+
foreach ($namedArgument in $attr.NamedArguments) {
14+
if ($namedArgument.ArgumentName -eq 'Key') {
15+
$key = $namedArgument.Argument.Value
16+
}
17+
elseif ($namedArgument.ArgumentName -eq 'Value') {
18+
$value = $namedArgument.Argument.Value
19+
}
20+
}
21+
if (-not $metadata[$key]) {
22+
$metadata[$key] = $value
23+
} else {
24+
$metadata[$key] = @($metadata[$key]) + $value
25+
}
26+
}
27+
28+
return $metadata
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
$parameterSetNames = @(foreach ($attr in $this.Attributes) {
2+
$reflectedType = $attr.TypeName.GetReflectionType()
3+
if ($reflectedType -ne [Management.Automation.ParameterAttribute]) {
4+
continue
5+
}
6+
foreach ($namedArgument in $attr.NamedArguments) {
7+
if ($namedArgument.ArgumentName -eq 'ParameterSetName') {
8+
$namedArgument.Argument.Value
9+
}
10+
}
11+
})
12+
13+
if ($parameterSetNames) {
14+
$parameterSetNames -as [string[]]
15+
} else {
16+
"__AllParameterSets" -as [string[]]
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$positions = @(
2+
:nextAttribute foreach ($attr in $this.Attributes) {
3+
$reflectedType = $attr.TypeName.GetReflectionType()
4+
if ($reflectedType -ne [Management.Automation.ParameterAttribute]) {
5+
continue
6+
}
7+
foreach ($namedArgument in $attr.NamedArguments) {
8+
if ($namedArgument.ArgumentName -eq 'Position') {
9+
$namedArgument.Argument.Value
10+
continue nextAttribute
11+
}
12+
}
13+
})
14+
15+
if ($positions.Length -gt 1) {
16+
$positions -as [int[]]
17+
} elseif ($positions) {
18+
$positions[0]
19+
} else {
20+
$null
21+
}

0 commit comments

Comments
 (0)