From ac54d05cfe2bb0a5c40d979837ac639db92ae0ae Mon Sep 17 00:00:00 2001 From: Yeming Liu Date: Fri, 5 Feb 2021 16:38:11 +0800 Subject: [PATCH] switch param best practice --- .../examples/switch-param-best-practice.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 documentation/development-docs/examples/switch-param-best-practice.md 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