AllowEmptyString 有什么技巧吗
我一直无法让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
I've never been able to get the AllowEmptyString validation attribute to work.
This:
function Get-InputString(
[parameter(mandatory=$true, position=0)][string][AllowEmptyString]$Str
)
{
$Str
}
Results in this:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少属性上的括号。请参阅 http://technet.microsoft.com/en-us/library/dd347600 .aspx
You're missing the parens on the attribute. See http://technet.microsoft.com/en-us/library/dd347600.aspx