Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 432 Bytes

switch-param-best-practice.md

File metadata and controls

21 lines (16 loc) · 432 Bytes

Switch Parameter Best Practice

DO NOT use IsParameterBound() on a switch parameter

// anti-pattern
if (this.IsParameterBound(c => c.PassThru))
{
    WriteObject(true);
}

It is possible to pass a $false to switch parameter, in that case, however, IsParameterBound() will still return true.

DO use if (SwitchParamName) to check a switch parameter

if (PassThru)
{
    WriteObject(true);
}