该OutputType
属性应该通过智能感知提供类型信息。但是它没有按预期工作。
我已经在 PSReadline 和 PowerShell ISE 中对此进行了测试,它们的工作方式相同。
以下是我正在使用的示例函数:
Function Get-FirstChar
{
[OutputType([String])]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)][string[]]$Strings
)
process {
foreach ($str in $Strings) {
$str.SubString(0, 1);
}
}
}
当我做:
"John","Simon" | Get-FirstChar | % { $_.<TAB> }
我得到建议(无论平台如何):
Equals GetHashCode GetType ToString
但是,当我这样做时:
("John","Simon" | Get-FirstChar).<TAB>
然后我得到所有的字符串方法等SubString
。
我也尝试了一个字符串数组String[]
作为输出类型,但它仍然不起作用:(
有人可以了解如何使用OutputType
属性来表示将从 powershell 函数返回一个或多个字符串吗?
谢谢