File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -2079,6 +2079,26 @@ function GetTypeString
20792079 return $TypeObjectHash.Name
20802080}
20812081
2082+ <#
2083+ You cannot just write 0..($n-1) because if $n == 0 you are screwed.
2084+ Hence this helper.
2085+ #>
2086+ function GetRange
2087+ {
2088+ Param (
2089+ [CmdletBinding ()]
2090+ [parameter (mandatory = $true )]
2091+ [int ]$n
2092+ )
2093+ if ($n -lt 0 ) {
2094+ throw " GetRange $n is unsupported: value less then 0"
2095+ }
2096+ if ($n -eq 0 ) {
2097+ return
2098+ }
2099+ 0 .. ($n - 1 )
2100+ }
2101+
20822102<#
20832103 This function proxies Get-Command call.
20842104
@@ -2174,7 +2194,7 @@ function MyGetCommand
21742194 Write-Error $errStr
21752195 }
21762196
2177- foreach ($i in 0 .. ( $parameters.Length - 1 )) {
2197+ foreach ($i in (GetRange $parameters.Length )) {
21782198 $typeObjectHash = New-Object - TypeName pscustomobject - Property @ {
21792199 Name = $parameterType [$i ].Name
21802200 IsGenericType = $parameterType [$i ].IsGenericType
@@ -2195,8 +2215,8 @@ function MyGetCommand
21952215
21962216 $psets = expand ' ParameterSets'
21972217 $psetsArray = @ ()
2198- foreach ($i in 0 .. ( $psets.Count - 1 )) {
2199- $parameters = getParams $i $psets .Count
2218+ foreach ($i in (GetRange $psets.Count )) {
2219+ $parameters = getParams $i
22002220 $psetsArray += @ (New-Object - TypeName pscustomobject - Property @ {
22012221 Name = $psets [$i ].Name
22022222 IsDefault = $psets [$i ].IsDefault
You can’t perform that action at this time.
0 commit comments