Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler committed Dec 10, 2024
1 parent b00ec93 commit 13bd746
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
```

- For other types, null values, empty strings, and empty arrays are converted
to `$false`. Other values, including empty hashtables convert to `$true`.
to `$false`.

```powershell
PS> [boolean]''
Expand All @@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
False
PS> [boolean]'Hello'
True
PS> [boolean]@(1,'Hello')
```

Other values, including empty hashtables convert to `$true`. Single-element
collections evaluate to the Boolean value of their one and only element.
Collections with more than 1 element are always `$true`.

```powershell
PS> [boolean]@(0)
False
PS> [boolean]@(0,0)
True
PS> [boolean]@{}
True
Expand Down Expand Up @@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
doesn't always work as intended. This syntax translates to:

```powershell
[byte[]] $bytes = 1..16
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
PS> [byte[]] $bytes = 1..16
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
```

Given that the type of **ArgumentList** is `[object[]]`, a single argument that
Expand All @@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
constructor with parameters that match the contents of the outer array.

```powershell
PS> $guid = New-Object System.Guid(@(, $bytes))
PS> [byte[]] $bytes = 1..16
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
PS> $guid
Guid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
```

- For other types, null values, empty strings, and empty arrays are converted
to `$false`. Other values, including empty hashtables convert to `$true`.
to `$false`.

```powershell
PS> [boolean]''
Expand All @@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
False
PS> [boolean]'Hello'
True
PS> [boolean]@(1,'Hello')
```

Other values, including empty hashtables convert to `$true`. Single-element
collections evaluate to the Boolean value of their one and only element.
Collections with more than 1 element are always `$true`.

```powershell
PS> [boolean]@(0)
False
PS> [boolean]@(0,0)
True
PS> [boolean]@{}
True
Expand Down Expand Up @@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
doesn't always work as intended. This syntax translates to:

```powershell
[byte[]] $bytes = 1..16
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
PS> [byte[]] $bytes = 1..16
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
```

Given that the type of **ArgumentList** is `[object[]]`, a single argument that
Expand All @@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
constructor with parameters that match the contents of the outer array.

```powershell
PS> $guid = New-Object System.Guid(@(, $bytes))
PS> [byte[]] $bytes = 1..16
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
PS> $guid
Guid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
```

- For other types, null values, empty strings, and empty arrays are converted
to `$false`. Other values, including empty hashtables convert to `$true`.
to `$false`.

```powershell
PS> [boolean]''
Expand All @@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
False
PS> [boolean]'Hello'
True
PS> [boolean]@(1,'Hello')
```

Other values, including empty hashtables convert to `$true`. Single-element
collections evaluate to the Boolean value of their one and only element.
Collections with more than 1 element are always `$true`.

```powershell
PS> [boolean]@(0)
False
PS> [boolean]@(0,0)
True
PS> [boolean]@{}
True
Expand Down Expand Up @@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
doesn't always work as intended. This syntax translates to:

```powershell
[byte[]] $bytes = 1..16
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
PS> [byte[]] $bytes = 1..16
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
```

Given that the type of **ArgumentList** is `[object[]]`, a single argument that
Expand All @@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
constructor with parameters that match the contents of the outer array.

```powershell
PS> $guid = New-Object System.Guid(@(, $bytes))
PS> [byte[]] $bytes = 1..16
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
PS> $guid
Guid
Expand Down

0 comments on commit 13bd746

Please sign in to comment.