using System.Collections;
using System.Collections.Generic;
public static void Main()
Console.WriteLine("IEnumerable<string> {0}", IsGenericEnumerable<IEnumerable<string>>());
Console.WriteLine("IEnumerable {0}", IsGenericEnumerable<IEnumerable>());
Console.WriteLine("IList<string> {0}", IsGenericEnumerable<IList<string>>());
Console.WriteLine("List<string> {0}", ImplementsGenericEnumerable<List<string>>());
Console.WriteLine("KeyValuePair<int,string> {0}", ImplementsGenericEnumerable<KeyValuePair<int,string>>());
public static bool IsGenericEnumerable<T>()
return typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(IEnumerable<>);
public static bool ImplementsGenericEnumerable<T>()
return typeof(T).IsGenericType && typeof(T).GenericTypeArguments.Length == 1 && typeof(IEnumerable<>).MakeGenericType(typeof(T).GenericTypeArguments).IsAssignableFrom(typeof(T));