1
我想要做的東西沿着這些路線脅迫數組字符串:PowerShell的當試圖調用C#可變參數的函數
$prefix = "C:\Users"
function prefix-path([string[]] $paths) {
Write-Output ([System.IO.Path]::Combine(@($prefix) + $paths))
}
prefix-path(1, 2, 3, 4)
我想收到C:\Users\1\2\3\4
但我得到的是這樣的:C:\Users 1 2 3 4
。引用1
,2
等沒有幫助。
我假設PowerShell出於某種原因假設我想將數組轉換爲字符串,然後繼續調用Combine(String)
版本,但我希望它顯然調用Combine(params String[])
。
當我包裝Combine它的作品。
function wrapped-combine([string[]] $path) {
Write-Output ([System.IO.Path]::Combine($path))
}
爲什麼會發生這種情況,我該如何正確編寫prefix-path
?