diff --git a/documentation/development-docs/examples/switch-param-best-practice.md b/documentation/development-docs/examples/switch-param-best-practice.md new file mode 100644 index 000000000000..3a6d6983185e --- /dev/null +++ b/documentation/development-docs/examples/switch-param-best-practice.md @@ -0,0 +1,21 @@ +# Switch Parameter Best Practice + +## DO NOT use `IsParameterBound()` on a switch parameter + +```csharp +// 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 + +```csharp +if (PassThru) +{ + WriteObject(true); +} \ No newline at end of file