In the below example I've got an IF
statement to determine which parameters send to Demo
when called recursively. If $y
were a boolean value rather than a switch I could simply call Demo -x $x -y $y
; but as a switch that's not a viable option.
function Demo {
[CmdletBinding()]
param (
[int]$x
,[switch]$y
)
process {
$x--
if ($x -gt 0) {
"$x - $($y.IsPresent)"
if($y.IsPresent) {
Demo -x $x -y
} else {
Demo -x $x
}
}
}
}
Demo 10 -y
Demo 10
Question
Is the above the correct way to handle this scenario, or does a cleaner option exist?