10using System.Collections.Generic;
14 internal static class TypeSystem
16 internal static Type GetElementType(Type seqType)
18 Type ienum = FindIEnumerable(seqType);
19 if (ienum ==
null)
return seqType;
20 return ienum.GetGenericArguments()[0];
23 private static Type FindIEnumerable(Type seqType)
25 if (seqType ==
null || seqType == typeof(
string))
29 return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
31 if (seqType.IsGenericType)
33 foreach (Type arg
in seqType.GetGenericArguments())
35 Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
36 if (ienum.IsAssignableFrom(seqType))
43 Type[] ifaces = seqType.GetInterfaces();
44 if (ifaces !=
null && ifaces.Length > 0)
46 foreach (Type iface
in ifaces)
48 Type ienum = FindIEnumerable(iface);
49 if (ienum !=
null)
return ienum;
53 if (seqType.BaseType !=
null && seqType.BaseType != typeof(
object))
55 return FindIEnumerable(seqType.BaseType);