/// <summary>
/// 判断类型是否为可操作的列表类型
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static bool IsList(this Type type)
{
if (typeof(System.Collections.IList).IsAssignableFrom(type))
{
return true;
}
foreach (var it in type.GetInterfaces())
{
if (it.IsGenericType && typeof(IList<>) == it.GetGenericTypeDefinition())
return true;
}
return false;
}
.
/// <summary>
/// 判断类型是否为列表类型
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static bool IsEnumerable(this Type type)
{
if (type.IsArray)
{
return true;
}
if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type))
{
return true;
}
foreach (var it in type.GetInterfaces())
if (it.IsGenericType && typeof(IEnumerable<>) == it.GetGenericTypeDefinition())
return true;
return false;
}