Fix Get-Help PSTypeName issue with -Parameter when only one parameter is declared#8754
Conversation
0e64b17 to
1d42ef2
Compare
There was a problem hiding this comment.
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.
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.
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.
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.
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,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile 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