Code inspection: Replace with OfType<T>().Count() (replace with OfType<T>().Count(..))
This inspection reports a LINQ query that casts elements with as, filters out null, and then counts elements matching another condition. The same logic is clearer with OfType<T>().Count(...).
Example
int count = items.Select(x => x as Person).Count(y => y != null && y.IsActive);
int count = items.OfType<Person>().Count(y => y.IsActive);
Quick-fix
Replace the Select(... as T).Count(y => y != null && ...) pattern with OfType<T>().Count(...).
29 March 2026