Skip to content

Bug #252

Description

@derekthecool

Description

Hi, thanks for the wonderful project! I use EZout in all of my powershell modules, thank you!

This is not actually a bug, instead it is either a lack of my understanding of using EZOut or perhaps powershell does not even allow this.

I'm trying to create a format view for raw primitive data types. In this case I really want to create a format view if for System.Int32.
Perhaps this is not even possible, but I thought I'd check with you here.
I really want to see decimal and hexadecimal format.

Here is my code I've attempted this with which I have saved in a file Numbers.format.ps1 in my module.

Write-FormatView `
    -TypeName 'System.Int32' `
    -Name DotsInt32View `
    -Property Hex `
    -VirtualProperty @{
    Hex = {
        "{0:X}" -f $_
    }
    Dec = {
        $_
    }
}

This generates the following in my output ps1xml file.

    <View>
      <Name>DotsInt32View</Name>
      <ViewSelectedBy>
        <TypeName>System.Int32</TypeName>
      </ViewSelectedBy>
      <TableControl>
        <TableHeaders>
          <TableColumnHeader>
            <Label>Hex</Label>
          </TableColumnHeader>
        </TableHeaders>
        <TableRowEntries>
          <TableRowEntry>
            <TableColumnItems>
              <TableColumnItem>
                <ScriptBlock>
        "{0:X}" -f $_
    </ScriptBlock>
              </TableColumnItem>
            </TableColumnItems>
          </TableRowEntry>
        </TableRowEntries>
      </TableControl>
    </View>

This output from Write-Host shows how I would love to have numbers formatted by default

$Number = 1234; Write-Host "$Number " -NoNewline; Write-Host "0x$([convert]::ToString($Number, 16).ToUpper())" -ForegroundColor Green
# prints this
# 1234 0x4D2

Reproducable Steps

None, not a bug

Links

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions