Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #252

Open
derekthecool opened this issue Dec 13, 2024 · 0 comments
Open

Bug #252

derekthecool opened this issue Dec 13, 2024 · 0 comments
Labels

Comments

@derekthecool
Copy link

derekthecool commented Dec 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant