Skip to content

Commit ffa64ca

Browse files
authored
switch param best practice (Azure#14142)
1 parent 37c1f4c commit ffa64ca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Switch Parameter Best Practice
2+
3+
## DO NOT use `IsParameterBound()` on a switch parameter
4+
5+
```csharp
6+
// anti-pattern
7+
if (this.IsParameterBound(c => c.PassThru))
8+
{
9+
WriteObject(true);
10+
}
11+
```
12+
13+
It is possible to pass a `$false` to switch parameter, in that case, however, `IsParameterBound()` will still return `true`.
14+
15+
## DO use `if (SwitchParamName)` to check a switch parameter
16+
17+
```csharp
18+
if (PassThru)
19+
{
20+
WriteObject(true);
21+
}

0 commit comments

Comments
 (0)