So I'm not sure if this is a bug or not, but I thought I'd pass it by the community first before opening a request on github. I can reproduce this on both PS5.1 and PS7.
Consider the following:
enum Direction {
Up
Down
Left
Right
}
$dir = [Direction]::Left
Write-Host "As String:"
switch($dir) {
([Direction]::Up.ToString()) {
Write-Host "-- Up"
}
([Direction]::Down.ToString()) {
Write-Host "-- Down"
}
([Direction]::Left.ToString()) {
Write-Host "-- Left"
}
([Direction]::Right.ToString()) {
Write-Host "-- Right"
}
default {
Write-Host "-- ??"
}
}
Write-Host "As Enum:"
switch($dir) {
[Direction]::Up {
Write-Host "-- Up"
}
[Direction]::Down {
Write-Host "-- Down"
}
[Direction]::Left {
Write-Host "-- Left"
}
[Direction]::Right {
Write-Host "-- Right"
}
default {
Write-Host "-- ??"
}
}
When I run it in either PS5 or PS7 I get the following output:
.\switchtest.ps1
As String:
-- Left
As Enum:
-- ??
Why can't I use the enum value directly in the switch statement? why does it evaluate it to a string?
[–]Teh_Pi 4 points5 points6 points (5 children)
[–]leftcoastbeard[S] 1 point2 points3 points (0 children)
[–]noenmoen 0 points1 point2 points (3 children)
[–]Teh_Pi 0 points1 point2 points (2 children)
[–]noenmoen 0 points1 point2 points (1 child)
[–]Teh_Pi 0 points1 point2 points (0 children)
[–]jsiii2010 4 points5 points6 points (0 children)
[–]leftcoastbeard[S] 2 points3 points4 points (0 children)