Created
January 22, 2011 22:43
-
-
Save stej/791578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function switchtest { | |
param([switch]$myswitch) | |
if ($myswitch) { 'switch is on' } | |
if (!$myswitch) { 'switch if off' } | |
#same as above | |
#if ($myswitch) { 'switch is on' } else { 'switch if off' } | |
write-host switch value is ([bool]$myswitch) and $myswitch | |
} | |
## test | |
PS> switchtest -myswitch | |
switch is on | |
switch value is True and True | |
PS> switchtest | |
switch if off | |
switch value is False and False |
A to jak obráceně? Switch je od toho, aby tam buď byl, nebo nebyl :) False je prostě defaultní hodnota. V tvým případě, pokud si na tom budeš trvat, tak je to spíš bool a ne switch.
Asi ti slo o obracenou logiku, co?
function Do-It {
param([switch] $delete = $true)
if ($delete -eq $true) { Remove-Item $tmp -force -recurse }
}
Do-It # smaze, protoze default je true
function Do-It {
param([switch] $keep)
if (!$keep) { Remove-Item $tmp -force -recurse }
}
Do-It # smaze, protoze keep je false
Přijímám patche ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jente já to chci přesně obráceně :)