-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
Why is [pscustomobject] the same as [psobject], even though a distinct [System.Management.Automation.PSCustomObject] type exists? #4344
Comments
I'm not aware of a good reason other than legacy reasons and concerns over breaking existing scripts. |
Thanks, @lzybkr. On a meta note: While I will certainly add that information to my personal notes, my concern is that these nuggets of information - sprinkled throughout the issues reported (#4347 is another recent example) - are not documented in an easily discoverable fashion. I've seen the I do wish we kept track of such issues, however, perhaps with something like an |
For now, I suggest using Thanks for your continued depth of research into these advanced topics. |
My pleasure, @SteveL-MSFT; I'm glad that you think so. Can I suggest a few more candidates for the
|
@mklement0 I marked the Issues. Could you please add there that we need document or open Issues in Doc repo? |
Thank you.
Do you mean I should also add a comment stating that documentation is needed? What would that gain us beyond the label? I think I'll hold off on creating documentation issues until it's clearer in what format and to what extent these advanced issues will be documented. |
Yes, we'll keep the time of who's going to document if it's not you. |
I don't know what you mean by that. |
Sorry, I meant that we need clear conclusion so that anyone can document it. |
@iSazonov: I see, good point. I'll see what I can do, but I hope that if I don't get around to it, others will still be able to glean from the existing comments what is documentation-worthy. |
A concrete example of where the identity of |
Personally, I've always found this behavior extremely confusing:
|
Agreed - that's a nice demonstration of the issues. The sense I'm getting is that Note that a > @{ Property = 'Value' } -is [psobject]
False
> ([psobject] @{ Property = 'Value'} ) -is [psobject]
True # !! Extra [psobject] wrapper was created. On a related note, #4343 shows that "know thyself" doesn't apply to custom objects with respect to the # Sample custom object.
> $co = [pscustomobject] @{ one = 1 }
> $co -is [pscustomobject]
True # OK
# Same with `$co -is [psobject]` due to the identity of [psobject] and [pscustombject]
> $co -is [System.Management.Automation.PSCustomObject]
True # OK
# Now try -as
> $co -as [System.Management.Automation.PSCustomObject]
# !! $null - $co doesn't know its own type |
Surprisingly,
[pscustomobject]
is the same as[psobject]
: both these type accelerators point to type[System.Management.Automation.PSObject]
, even though there is a distinct[System.Management.Automation.PSCustomObject]
type.Mostly, this conflation goes unnoticed (and has come up before - see #2295), but:
what is the rationale for it?
it makes for surprising behavior on occasion - see below.
Environment data
The text was updated successfully, but these errors were encountered: