Highlight wrong use of OfType<T>()

Is there a way to allow ReSharper to highlight incorrect use of OfType<T>(), i.e. when T is chosen such that it never will return any elements.

Here is an example:

internal class Car
{
};

internal class RollsRoyce : Car
{
};

internal class Bicycle
{
};

...

List<Car> cars = new List<Car>();
List<RollsRoyce> expensiveCars = new List<RollsRoyce>();

IEnumerable<RollsRoyce> list1 = cars.OfType<RollsRoyce>();
IEnumerable<Bicycle> list2 = cars.OfType<Bicycle>();


In this example, list2 always will be empty, because Bicycle does not derive from Car.

I have tried using this ReSharper highlighting expression:

$expr$.OfType<$type$>()

but I have found no way to specify that $type$ should be a type that is not derived of $expr$'s class argument's type.

Please sign in to leave a comment.