我怎么知道省略了 PowerShell 函数参数 [英] How can I know that PowerShell function parameter is omitted

查看:23
本文介绍了我怎么知道省略了 PowerShell 函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这样的函数:

function Test($foo, $bar)
{
  ...
}

我们可以称之为:

Test -foo $null
Test

我怎么知道 -foo 什么时候被省略,什么时候是 $null?

How can I know when the -foo was omitted, and when it was $null?

推荐答案

如果您使用的是 Powershell V2 或更高版本,您可以使用 $PSBoundParameters 变量,它是一个字典,列出当前范围内的所有绑定参数.

If you are using Powershell V2 or later, you can use the $PSBoundParameters variable which is a dictionary that lists all bound parameters at current scope.

参见这个 讨论它的博文.

这篇关于我怎么知道省略了 PowerShell 函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆