Why don't you use Contains
and target.GetType
?
bool ar isSupported = supportedTypes.Contains(target.GetType());
or Any
bool isSupported = supportedTypes.Any(t => t == target.GetType());
(don't use Enumerable.Count
if you just want to know if a sequence contains a matching element, that is rather inefficient if the sequnce is large or the predicate is expensive)
Edit: If you want to take inheritance into account you can use Type.IsAssignableFrom
:
var isSupported = supportedTypes.Any(t => target.GetType().IsAssignableFrom(t));
- The
is
operator is used to check whether an instance is compatible to a given type.
- The
IsAssignableFrom
method is used to check whether a Type is compatible with a given type.
Determines whether an instance of the current Type can be assigned
from an instance of the specified Type.