using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Foo { public static Type GetEnumerableType(Type type) { if (type == null) throw new ArgumentNullException("type"); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) return type.GetGenericArguments()[0]; var iface = (from i in type.GetInterfaces() where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>) select i).FirstOrDefault(); if (iface == null) throw new ArgumentException("Does not represent an enumerable type.", "type"); return GetEnumerableType(iface); } static void Main() { foreach (var type in new[] { typeof(IEnumerable), typeof(List), typeof(EnumerableTest) }) { Console.WriteLine("{0}: {1}", type.FullName, GetEnumerableType(type).FullName); } } } class EnumerableTest : IEnumerable, IEnumerable { IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } public IEnumerator GetEnumerator() { throw new NotImplementedException(); } }