|
17 | 17 | # * As a ```[ScriptBlock]``` containing only parameters. |
18 | 18 | [Parameter(ValueFromPipelineByPropertyName)] |
19 | 19 | [ValidateScriptBlock(ParameterOnly)] |
20 | | - [ValidateTypes(TypeName={[Collections.IDictionary], [string],[Object[]], [Scriptblock]})] |
| 20 | + [ValidateTypes(TypeName={ |
| 21 | + [Collections.IDictionary], |
| 22 | + [string], |
| 23 | + [Object[]], |
| 24 | + [Scriptblock], |
| 25 | + [Reflection.PropertyInfo], |
| 26 | + [Reflection.PropertyInfo[]], |
| 27 | + [Reflection.ParameterInfo], |
| 28 | + [Reflection.ParameterInfo[]], |
| 29 | + [Reflection.MethodInfo], |
| 30 | + [Reflection.MethodInfo[]] |
| 31 | + })] |
21 | 32 | $Parameter, |
22 | 33 |
|
23 | 34 | # The dynamic parameter block. |
|
147 | 158 | $parameter |
148 | 159 | } |
149 | 160 | } |
| 161 | + elseif ($parameter -is [Reflection.PropertyInfo] -or |
| 162 | + $parameter -as [Reflection.PropertyInfo[]] -or |
| 163 | + $parameter -is [Reflection.ParameterInfo] -or |
| 164 | + $parameter -as [Reflection.ParameterInfo[]] -or |
| 165 | + $parameter -is [Reflection.MethodInfo] -or |
| 166 | + $parameter -as [Reflection.MethodInfo[]] |
| 167 | + ) { |
| 168 | + if ($parameter -is [Reflection.MethodInfo] -or |
| 169 | + $parameter -as [Reflection.MethodInfo[]]) { |
| 170 | + $parameter = @(foreach ($methodInfo in $parameter) { |
| 171 | + $methodInfo.GetParameters() |
| 172 | + }) |
| 173 | + } |
| 174 | + |
| 175 | + foreach ($prop in $Parameter) { |
| 176 | + if ($prop -is [Reflection.PropertyInfo] -and -not $prop.CanWrite) { continue } |
| 177 | + $paramType = |
| 178 | + if ($prop.ParameterType) { |
| 179 | + $prop.ParameterType |
| 180 | + } elseif ($prop.PropertyType) { |
| 181 | + $prop.PropertyType |
| 182 | + } else { |
| 183 | + [PSObject] |
| 184 | + } |
| 185 | + $ParametersToCreate[$prop.Name] = |
| 186 | + @( |
| 187 | + $parameterAttribute = "[Parameter(ValueFromPipelineByPropertyName)]" |
| 188 | + $parameterAttribute |
| 189 | + if ($paramType -eq [boolean]) { |
| 190 | + "[switch]" |
| 191 | + } else { |
| 192 | + "[$($paramType -replace '^System\.')]" |
| 193 | + } |
| 194 | + '$' + $prop.Name |
| 195 | + ) -ne '' |
| 196 | + } |
| 197 | + } |
150 | 198 | } |
151 | 199 |
|
152 | 200 | # If there is header content, |
|
0 commit comments