ReSharper 2026.1 Help

コードインスペクション:OfType<T>().Count() に置き換え(OfType<T>().Count(..) に置き換え)

このインスペクションは、 as で要素をキャストし、 null を除外し、別の条件に一致する要素をカウントする LINQ クエリを報告します。 同じロジックは OfType<T>().Count(...) を使用するとより明確になります。

サンプル

int count = items.Select(x => x as Person).Count(y => y != null && y.IsActive);
int count = items.OfType<Person>().Count(y => y.IsActive);

クイックフィックス

Select(... as T).Count(y => y != null && ...) パターンを OfType<T>().Count(...) に置き換えてください。

2026 年 6 月 12 日