Get-Listbox.ps1 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function Get-Listbox() {
  2. cmdlet `
  3. -DefaultParameterSet Type `
  4. param(
  5. [Parameter(ParameterSetName="Type", ValueFromPipeline=$true, Mandatory=$true)]
  6. [Type]
  7. $type,
  8. [Parameter(ParameterSetName="Enum", ValueFromPipeline=$true, Mandatory=$true)]
  9. [Enum]
  10. $enum,
  11. [Parameter(ParameterSetName="String", ValueFromPipeline=$true, Mandatory=$true)]
  12. [string]
  13. $string
  14. )
  15. Begin{
  16. $listItems = @()
  17. }
  18. Process
  19. {
  20. switch ($psCmdlet.ParameterSetName) {
  21. "Type" {
  22. if ($type.IsEnum) {
  23. $listItems+= [Enum]::GetValues($type)
  24. }
  25. }
  26. "Enum" {
  27. $listItems+= [Enum]::GetValues($enum.GetType())
  28. }
  29. "String" { $listItems += $string }
  30. }
  31. }
  32. End
  33. {
  34. $listbox = New-Object Windows.Controls.Listbox
  35. $listBox.ItemsSource = $listItems | Select -unique
  36. $listBox
  37. }
  38. }