I was working on a project that required a determination if the type was an IEnumerable collection of some type.
Using a bit of reflection and the handy-dandy GetGenericTypeDefinition method, I arrive at this:
Code Snippet
- public static bool IsIEnumerableOfT(Type type)
- {
- return type.GetInterfaces().Any(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof (IEnumerable<>)) ;
- }
Happy Coding!