2
Je n'ai jamais réussi à obtenir l'attribut de validation AllowEmptyString pour fonctionner.Y at-il une astuce à AllowEmptyString
Ce:
function Get-InputString(
[parameter(mandatory=$true, position=0)][string][AllowEmptyString]$Str
)
{
$Str
}
Résultats: dans cette
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
Il m'a fallu une minute pour voir ça. Au lieu de copier/coller votre repro, je tapais l'attribut et je tapais inconsciemment les parens. Désolé pour mon commentaire inutile. – xcud
Merci. Cela aurait été bien s'ils avaient les parenthèses dans l'échantillon dans l'aide de PowerShell. – OldFart
Je regarde l'exemple dans about_advanced_functions et je vois parens - où est l'échantillon dont vous parlez et qui n'a pas les parenthèses? – x0n