Back to Devexpress

CRR0009 - Subsequent if-statements have identical conditions

coderushforroslyn-118107-static-code-analysis-analyzers-library-crr0009-subsequent-if-statements-have-identical-conditions.md

latest1.1 KB
Original Source

CRR0009 - Subsequent if-statements have identical conditions

  • Feb 28, 2025

This analyzer detects a conditional statement followed by another conditional statement with a similar condition. See the example below.

csharp
if (condition) // CRR0009
    DoSomething();

if (condition)
    DoSomethingElse();
vb
If condition Then ' CRR0009
    DoSomething()
End If

If condition Then
    DoSomethingElse()
End If

Subsequent conditional statements with identical conditions can always be combined into a single conditional statement. Use the Combine/Split Conditional(s) refactoring to combine them automatically.

csharp
if (condition){
    DoSomething();
    DoSomethingElse();
}
vb
If condition Then
    DoSomething()
    DoSomethingElse()
End If

See Also

Suppress Analyzers