private static Type GetEnumerableType(Type type)
{
if (type == typeof(String))
{
return typeof(String);
}
if (type.IsGenericType)
{
if (type.GetGenericArguments().Count() == 1)
{
return type.GetGenericArguments().First();
}
return (from intType in type.GetInterfaces()
where intType.GetGenericTypeDefinition() == typeof(IEnumerable<>)
select intType.GetGenericArguments()[0]).FirstOrDefault();
}
return type;
}