Skip to content

Commit ef2a05f

Browse files
author
James Brundage
committed
New-PipeScript: Adding -WeaklyTyped (Fixes #174)
1 parent 24f115c commit ef2a05f

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

New-PipeScript.ps1.ps1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,19 @@ HTTP Accept indicates what content types the web request will accept as a respon
8585

8686
# If provided, will add inline help to parameters.
8787
[Collections.IDictionary]
88-
$ParameterHelp
88+
$ParameterHelp,
89+
90+
<#
91+
If set, will weakly type parameters generated by reflection.
92+
93+
1. Any parameter type implements IList should be made a [PSObject[]]
94+
2. Any parameter that implements IDictionary should be made an [Collections.IDictionary]
95+
3. Booleans should be made into [switch]es
96+
4. All other parameter types should be [PSObject]
97+
#>
98+
[Alias('WeakType', 'WeakParameters', 'WeaklyTypedParameters', 'WeakProperties', 'WeaklyTypedProperties')]
99+
[switch]
100+
$WeaklyTyped
89101
)
90102

91103
begin {
@@ -205,7 +217,7 @@ HTTP Accept indicates what content types the web request will accept as a respon
205217

206218
foreach ($prop in $Parameter) {
207219
if ($prop -is [Reflection.PropertyInfo] -and -not $prop.CanWrite) { continue }
208-
$paramType =
220+
$paramType =
209221
if ($prop.ParameterType) {
210222
$prop.ParameterType
211223
} elseif ($prop.PropertyType) {
@@ -222,7 +234,18 @@ HTTP Accept indicates what content types the web request will accept as a respon
222234
$parameterAttribute
223235
if ($paramType -eq [boolean]) {
224236
"[switch]"
225-
} else {
237+
} elseif ($WeaklyTyped) {
238+
if ($paramType.GetInterface([Collections.IDictionary])) {
239+
"[Collections.IDictionary]"
240+
}
241+
elseif ($paramType.GetInterface([Collections.IList])) {
242+
"[PSObject[]]"
243+
}
244+
else {
245+
"[PSObject]"
246+
}
247+
}
248+
else {
226249
"[$($paramType -replace '^System\.')]"
227250
}
228251
'$' + $prop.Name

0 commit comments

Comments
 (0)