diff --git a/src/Transform/TransformBase.cs b/src/Transform/TransformBase.cs index d85daff0..1f8064c6 100644 --- a/src/Transform/TransformBase.cs +++ b/src/Transform/TransformBase.cs @@ -100,7 +100,8 @@ commandInfo is CmdletInfo || // We can also simplify the string if desired. private string GetAdjustedTypename(Type t, bool simplify = false) { - string tName = simplify ? LanguagePrimitives.ConvertTo(t) : t.FullName; + var t2 = Nullable.GetUnderlyingType(t) ?? t; + string tName = simplify ? LanguagePrimitives.ConvertTo(t2) : t2.FullName; return tName; } @@ -847,7 +848,14 @@ protected List GetInputOutputItemsFromHelp(dynamic typesInfo) // We also will remove trailing [] because we should generally return singletons private string FixUpTypeName(string typename) { - string fixedString = typename.Trim(); + // If the type is a generic type, we need to remove the backtick and the number. + string fixedString = typename.Replace("System.Nullable`1[[", string.Empty).Trim(); + int commaIndex = fixedString.IndexOf(','); + if (commaIndex >= 0) + { + fixedString = fixedString.Substring(0, commaIndex).Trim(); + } + if (fixedString.EndsWith("[]")) { fixedString = fixedString.Remove(fixedString.Length - 2); diff --git a/test/Pester/ConvertToCommandHelp.Tests.ps1 b/test/Pester/ConvertToCommandHelp.Tests.ps1 index 6a2aafa8..bed2bb2e 100644 --- a/test/Pester/ConvertToCommandHelp.Tests.ps1 +++ b/test/Pester/ConvertToCommandHelp.Tests.ps1 @@ -141,6 +141,20 @@ Describe "New-CommandHelp tests" { BeforeAll { $cmd = Get-Command Get-Command $ch = $cmd | New-CommandHelp + + function global:Test-InputOutputTypes + { + [CmdletBinding()] + [OutputType()] + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [Nullable[int]]$InputString + ) + + Write-Output "Processed: $InputString" + } + + $io = New-CommandHelp -Command (Get-Command Test-InputOutputTypes) } It "Should have the proper number of output types" { @@ -176,12 +190,16 @@ Describe "New-CommandHelp tests" { @{ Type = "System.Management.Automation.CommandTypes" } @{ Type = "System.Int32" } @{ Type = "Microsoft.PowerShell.Commands.ModuleSpecification[]" } - @{ Type = "System.String" } + @{ Type = "System.String[]" } @{ Type = "System.Management.Automation.SwitchParameter" } ) { param ($type) $ch.inputs.typename | Should -Contain $type } - } + It "Should not have Nullable in the input type" { + $io.inputs.typename | Should -Not -Contain "Nullable" + $io.inputs.typename | Should -Be "System.Int32" + } + } } \ No newline at end of file