我用 C# 编写了一个 Cmdlet。是否可以为特定字符串参数(“PackageId”是此示例)提供所有可能的值?
public sealed class InstallPackageCommand : PSCmdlet
{
[Parameter(Position = 0, Mandatory = true)]
public string PackageId { get; set; }
protected override void BeginProcessing()
{
//...
}
}
最佳答案
您可以在您的属性上为该参数使用 ValidateSetAttribute
,例如:
[ValidateNotNullOrEmpty]
[ValidateSet(new string[] {"a","b","c"})]
[Parameter(Position = 0, Mandatory = true)]
public string PackageId { get; set; }
关于c# - PowerShell参数取值建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19709179/