0
我想创建log
功能的工作方式类似于Write-Host
,我可以给它特设的参数与一些参数一起:功能的优先级为未申报的参数在声明
function log ([int]$ident=0, [switch]$notime) {
$now = (Get-Date).ToString('s')
Write-Host $(if (!$NoTime) {now}) $($args | % { ' '*$ident*2 + $_ })
}
log 'test 1' 'test 2' # Cannot convert value "test 1" to type "System.Int32"
log 'test 1' 'test 2' -Ident 1 #Works
我知道我可以获取未声明的参数$args
或使用ValueFromRemainingArguments
属性,但这要求我改变调用函数的方式,因为声明的函数参数将收集它们。
不知道'PositionalBinding'。谢谢一堆。 – majkinetor