Code inspection: Replace with SingleOrDefault($args$)
This inspection reports a guarded conditional expression that first checks another condition and then uses Any(...) ? Single(...) : null. When the guard is true, the inner Any/Single pair can be simplified to SingleOrDefault(...).
Example
var item = isEnabled && items.Any(x => x.IsActive)
? items.Single(x => x.IsActive)
: null;
var item = isEnabled
? items.SingleOrDefault(x => x.IsActive)
: null;
Quick-fix
Replace the guarded Any(...) ? Single(...) : null pattern with SingleOrDefault(...).
29 March 2026