How can I check the type of an object against a list of types?
- by RookieRick
Given a collection
IEnumerable<Type> supportedTypes
What's the best way to check whether a given object is one of those types (or a derived type)?
My first instinct was to do something like:
// object target is a parameter passed to the method in which I'm doing this.
if (supportedTypes.Count( supportedType => target is supportedType ) > 0)
{
// Yay my object is of a supported type!!!
}
..but that doesn't seem to be working. Can I not use the "is" keyword in a lambda expression like this?