回复 8# 小白龙 - function Global:Get-EnumValues {
- [CmdletBinding()]
- [OutputType([string[]])]
- param (
- [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
- [ValidateNotNullOrEmpty()]
- [ValidateScript( { $_.IsSubclassOf([Enum]) })]
- [Type]$EnumType,
- [Parameter(Mandatory = $false, Position = 1)]
- [ValidateNotNullOrEmpty()]
- [int]$NameWidth = -20,
- [Parameter(Mandatory = $false, Position = 2)]
- [ValidateNotNullOrEmpty()]
- [int]$ValueWidth = 8,
- [Parameter(Mandatory = $false, Position = 3)]
- [ValidateNotNullOrEmpty()]
- [int]$HexWidth = 8,
- [Parameter(Mandatory = $false, Position = 4)]
- [ValidateNotNullOrEmpty()]
- [int]$BinaryWidth = 16,
- [Parameter(Mandatory = $false, Position = 5)]
- [switch]$NoSplitBinary
- )
- [char]$c = '0'
- [Enum]::GetNames($EnumType) | ForEach-Object {
- $value = $EnumType::$_
- $strBinary = [Convert]::ToString([long]$value, 2).PadLeft(${BinaryWidth}, $c)
- if (!$NoSplitBinary) {
- $strBinary = $strBinary -replace ".{8}(?!=$)", "$& "
- }
- "{0,${NameWidth}:g} : {1,${ValueWidth}:d} {2,${HexWidth}:x} {3,${BinaryWidth}}" -f `
- @($_, $value, $value, $strBinary)
- }
- }
复制代码
|