Code inspection: Replace with OfType<T>().First() (replace with OfType<T>().First(..))
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>().First(...).
Example
var first = items.Select(x => x as Person).First(y => y != null && y.IsActive);
var first = items.OfType<Person>().First(y => y.IsActive);
Quick-fix
Replace the Select(... as T).First(y => y != null && ...) pattern with OfType<T>().First(...).
29 March 2026