Есть ли какая-то хитрость для AllowEmptyString - PullRequest
2 голосов
/ 22 июня 2010

Мне никогда не удавалось заставить работать атрибут проверки AllowEmptyString.

This:

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

1 Ответ

2 голосов
/ 22 июня 2010

Вам не хватает символов в атрибуте. Смотри http://technet.microsoft.com/en-us/library/dd347600.aspx

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

    $Str
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...