Code inspection: Replace with OfType<T>().FirstOrDefault() (replace with OfType<T>().FirstOrDefault(..))
This inspection reports a LINQ query that casts elements with as, filters out null, and then looks for the first element matching an additional condition. The same query is easier to read with OfType<T>().FirstOrDefault(...).
Example
var first = items.Select(x => x as Person).FirstOrDefault(y => y != null && y.IsActive);
var first = items.OfType<Person>().FirstOrDefault(y => y.IsActive);
Quick-fix
Replace the Select(... as T).FirstOrDefault(y => y != null && ...) pattern with OfType<T>().FirstOrDefault(...).
29 March 2026