gpt4 book ai didi

powershell - 是否有一些技巧允许AllowEmptyString

转载 作者:行者123 更新时间:2023-12-02 23:49:10 25 4
gpt4 key购买 nike

我从来没有能够使AllowEmptyString验证属性起作用。

这个:

function Get-InputString(
[parameter(mandatory=$true, position=0)][string][AllowEmptyString]$Str
)
{
$Str
}

结果:
PS C:\> Get-InputString ''
Unable to find type [AllowEmptyString]: make sure that the assembly containing this type is loaded.
At line:2 char:71
+ [parameter(mandatory=$true, position=0)][string][AllowEmptyString] <<<< $Str
+ CategoryInfo : InvalidOperation: (AllowEmptyString:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

最佳答案

您缺少该属性的括号。参见http://technet.microsoft.com/en-us/library/dd347600.aspx

function Get-InputString
{
Param(
[Parameter(Mandatory=$true, Position=0)]
[AllowEmptyString()]
[String]
$Str
)

$Str
}

关于powershell - 是否有一些技巧允许AllowEmptyString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3096542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com