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
Fix Get-Help
PSTypeName
issue with -Parameter
when only one parameter is declared
#8754
Conversation
0e64b17
to
1d42ef2
Compare
PSObject[] prmtArray = (PSObject[])LanguagePrimitives.ConvertTo( | ||
prmts.Properties["parameter"].Value, | ||
paramAsPSObjArray != null ? paramAsPSObjArray : param, |
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.
You could probably condense much of this into the ternary statement, if I'm reading this right...
paramAsPSObjArray != null ? paramAsPSObjArray : param, | |
paramPSObjArray == null ? paramPSObjArray : new[] { (PSObject)prmts.Properties["parameter"].Value }, |
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.
The problem is that param is not necessarily PSObject or PSObject[]. It can also be object which makes the cast failure prone.
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.
You can do PSObject.AsPSObject(obj)
to safely convert object -> PSObject, but I'm not sure whether that would completely resolve the issue.
That method will also no-op if the input object is already a 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.
I don't think it resolves the issue since that method will attempt to create a PSObject from object. What I'm doing here is essentially trying to use the object as is in the form of a PSObject and if it doesn't work then I will just pass the object along to ConvertTo as was done previously. ConvertTo itself knows what to do with a plain object in regards to transforming it into a 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.
I'm not 100% sure, but I think that's more or less just what ConvertTo would do itself... I'd have to chase down the convoluted code paths in there, though. I'm sure it's OK to use ConvertTo, though. 🙂
40bca28
to
0c67a87
Compare
Get-Help
PSTypeName
issue with -Parameter
when only one parameter is declared
@pougetat Thank you for your contribution! |
PR Summary
Fix #8697 'Get-Help -Parameter does not correctly set PSTypeName when one parameter is declared'.
PR Context
This issue occurs for the following reason :
My fix is to manipulate a PSObject[] instead of a PSObject even in the event that it only contains one parameter.
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.[feature]
to your commit messages if the change is significant or affects feature tests