IIf Side Effect
Identifies Functions or Properties referenced by the TruePart(second argument) or FalsePart(third argument) of the IIf built-in function.
Reasoning
All arguments of any function/procedure call are always evaluated before the function is invoked so that their respective values can be passed as parameters. Even so, the IIf Function's behavior is sometimes mis-interpreted to expect that ONLY the 'TruePart' or ONLY the 'FalsePart' expression will be evaluated based on the result of the first argument expression. Consequently, the IIf Function can be a source of unanticipated side-effects and errors if the user does not account for the fact that both the TruePart and FalsePart arguments are always evaluated.
Default severity
Warning
Inspection type
CodeQualityIssues
Examples
This example should trigger a result
This example should trigger a result
This example should NOT trigger a result
Rubberduck.CodeAnalysis.Inspections.Concrete.IIfSideEffectInspection.cs (Prerelease-v2.5.9.6289)