-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Make -is [pscustomobject] and -as [pscustomobject] work meaningfully #11921
Comments
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
1 similar comment
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Note: The following discusses the issue with respect to the
-is
operator, but the same applies to the-as
operator (which is currently broken even when using the full type name - see #4343).-is [pscustomobject]
(and analogously-as [pscustomobject]
) should work meaningfully as follows:Background Information
Currently, the only way to test meaningfully for whether a given value is a custom object is to do the use the full type name:
Surprisingly,
[pscustomobject]
does not work meaningfully:The reason is that
[pscustomobject]
is unexpectedly the same as[psobject]
(!), i.e., it is type accelerator forSystem.Management.Automation.PSObject
rather than forSystem.Management.Automation.PSCustomObject
, for historical reasons (see #4344).Therefore, any
[psobject]
-wrapped .NET object returns$true
for-is [pscustomobject]
, which is both confusing and virtually useless.Note that there already is precedent for situationally distinguishing between
[pscustomobject]
and[psobject]
, namely in the context of custom-object literals via syntactic sugar[pscustomobject] @{ ... }
(constructs a custom object), which doesn't work with[psobject] @{ ... }
(constructs a hashtable and uselessly wraps it in[psobject]
).See also:
AutomationNull Behaviour #9997, where meaningful use of
-is [AutomationNull]
is proposed to allow distinguishing[System.Management.Automation.Internal.AutomationNull]::Value
values from true$null
values.Pending PR Add -is $null and -isnot $null support to operators and Where-Object #10704, which implements the ability to use
-is $null
to test for$null
values.The text was updated successfully, but these errors were encountered: