仅当提供其他参数时,我才需要应用条件开关参数。任何机构都可以让我知道如何在 C# 中实现这一点
我希望在 powershell 终端上可以访问以下方式命令。
编辑
Get-Parameter # this will process other path of the code and won't throw an error. (e.g. Not providing name of parameter, it would return all parameters in the container )
Get-Parameter -Name "Epics" -Writeable # writeable is switch parameter
Get-Parameter -Writeable # should throw an error ( Writeable switch only allows when Name parameter is provided.
以下是 C# commandlet 代码。
[Cmdlet(VerbsCommon.Get, "Parameter")]
public class GetParameter : PSCmdlet
{
[Parameter(
Position = 1,
Mandatory = false,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true, ParameterSetName = "Name")
]
public string Name { get; set; }
[Parameter(Mandatory = true, ParameterSetName = "Name" ,ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
public SwitchParameter Writeable { get; set; } = false;
}