-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Use PSCustomObject instead of PSObject for synthetic types. #25363
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
base: master
Are you sure you want to change the base?
Conversation
| { | ||
| Members = membersTypes; | ||
| if (type != typeof(PSObject)) | ||
| if (type != typeof(PSCustomObject)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above in lines 914 and 916 I see two Create() methods with 7 uses - all of them are subject to this change. Please describe all of them in the PR description (not only Hashtable). Perhaps they should also be reflected in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has already been described:
This PR updates the synthetic types used for tab completion and type inference to use PSCustomObject instead of PSObject as the default type name.
In other words, every instance where the synthetic type would say it's a "PSObject" has been updated to say it's a "PSCustomObject". This is in line with what we get at runtime, for example:
PS C:\> (ls | select -First 1 Name,FullName).GetType()
FullName BaseType
-------- --------
System.Management.Automation.PSCustomObject System.Object
PS C:\>
As for the specific overload references you mention, the first one is exclusively used for Group-Object where the specified typename is Microsoft.PowerShell.Commands.GroupInfo so it's unaffected by these changes.
The second overload is used by Select-Object, Hashtable type inference, and convert expressions where the target type is psobject/pscustomobject. This is where I've made a slight fix so that: [psobject]@{Test = ls} is correctly treated as a hashtable, as the resulting object would just be a standard hashtable with an invisible psobject wrapper around it.
Everything should already be covered by existing tests that were modified for this change, or added as part of the change.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
| if (type.Type == typeof(PSObject) && type is not PSSyntheticTypeName) | ||
| if (type.Type == typeof(PSObject)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the type is not PSSyntheticTypeName check removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that back in: #21184 so that it could get members for synthetic types but now that synthetic types aren't PSObject anymore, that exclusion is no longer needed.
…sitor.cs Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
PR Summary
This PR updates the synthetic types used for tab completion and type inference to use PSCustomObject instead of PSObject as the default type name. This will remove the irrelevant and unusable PSObject members like
BaseObjectandImmediateBaseObjectfrom the tab completion when working with synthetic types, like:$Data = ls | select Name,Length; $Data.<Tab>and when dealing with custom objects in general:$Var1 = [pscustomobject]@{Test = ls}; $Var1.<Tab>.This also fixes a minor issue where attempting to wrap a hashtable in a PSObject would remove the hashtable members:
$Var1 = [psobject]@{Test = ls}; $Var1.<Tab>so you didn't see members like "keys" and "Count".PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header