Linux
Nginx
数据库
Python
PHP
C#
.NET
WPF
MAUI
Blazor
WinForm
帝国CMS
AKCMS
Typecho
织梦CMS
Visual Studio
Windows
Mac
Web前端
数据采集
运营
产品
摩托车
电影
杂事
/// <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;
本文作者:唐宋元明清
信息来源:cnblogs.com 唐宋元明清
所属分类:
C#
上一篇:
C# 反射 操作列表类型属性
下一篇:
C#中List对象去重的三种方法
Power by Typecho. Theme by Puma. Written by 董川民-
独立开发者
渝ICP备16006207号-2
渝公网安备 50011202503233号
友情链接: