CodeQL library for C#
codeql/csharp-all 7.4.2 (changelog, source)
Search

Predicate missedFirstOrDefaultOpportunity

Holds if foreach statement fes could be converted to a .FirstOrDefault() call. That is, the loop contains a single if statement that accesses the loop variable, returns the loop variable when the condition matches, and is followed by a default return.

Import path

import Linq.Helpers
predicate missedFirstOrDefaultOpportunity(ForEachStmtGenericEnumerable fes, IfStmt is)