Skip to content

Commit 07b7a53

Browse files
author
James Brundage
committed
ParameterAst: Adding .Binding and .DefaultBindingProperty (re #305)
1 parent 666d138 commit 07b7a53

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Types/ParameterAST/get_Binding.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$isBindable = $false
2+
foreach ($attr in $this.Attributes) {
3+
$reflectedType = $attr.TypeName.GetReflectionType()
4+
if ((-not $reflectedType) -or
5+
$reflectedType -notin [ComponentModel.DefaultBindingPropertyAttribute],
6+
[ComponentModel.BindableAttribute],
7+
[ComponentModel.ComplexBindingPropertiesAttribute]) {
8+
continue
9+
}
10+
11+
$positionalArguments = @(
12+
foreach ($positionalParameter in $attr.PositionalArguments) {
13+
$positionalParameter.Value
14+
}
15+
)
16+
$realAttribute =
17+
if ($positionalArguments) {
18+
$reflectedType::new($positionalArguments)
19+
} else {
20+
$reflectedType::new()
21+
}
22+
23+
24+
foreach ($namedArgument in $attr.NamedArguments) {
25+
if ($namedArgument.ArgumentName -eq 'Name') {
26+
$realAttribute.$($namedArgument.ArgumentName) = $namedArgument.Argument.Value
27+
}
28+
}
29+
$realAttribute
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$isBindable = $false
2+
foreach ($attr in $this.Attributes) {
3+
$reflectedType = $attr.TypeName.GetReflectionType()
4+
if ($reflectedType -ne [ComponentModel.DefaultBindingPropertyAttribute]) {
5+
if ($reflectedType -eq [ComponentModel.BindableAttribute]) {
6+
if ($attr.PositionalArguments.Value -eq $false) {
7+
return ''
8+
} else {
9+
$isBindable = $true
10+
}
11+
}
12+
continue
13+
}
14+
15+
foreach ($positionalParameter in $attr.PositionalArguments) {
16+
return $positionalParameter.Value
17+
}
18+
19+
foreach ($namedArgument in $attr.NamedArguments) {
20+
if ($namedArgument.ArgumentName -eq 'Name') {
21+
return $namedArgument.Argument.Value
22+
}
23+
}
24+
}
25+
26+
27+
if ($isBindable) {
28+
return $this.Name.VariablePath.ToString()
29+
} else {
30+
return ''
31+
}

0 commit comments

Comments
 (0)