Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/187ac2a5d13877f0d8732aab62cae0bd to your computer and use it in GitHub Desktop.
Save PlagueHO/187ac2a5d13877f0d8732aab62cae0bd to your computer and use it in GitHub Desktop.
PowerShell example using an enumerator type to map colour name to value with a default value set for invalid values
$colourName = 'grey'
# Only needs to be declared once
enum colour {
red = 0xFF0000
green = 0x00FF00
blue = 0x0000FF
white = 0xFFFFFF
}
$colourValue = [colour]::white
if (-not [colour]::TryParse($colourName, $true, [ref] $colourValue)) {
return 0x0
} else {
return $colourValue.value__
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment