C# 判断变量是不是集合类型
今天碰到个方法,参数类型是object,内部有SerializeUtil.JsonSerialize(value);或value.ToString()的逻辑,需要判断
// 使用
if (IsList(value.GetType()))
{
var a = SerializeUtil.JsonSerialize(value);
}
/// <summary>
/// 判断类型是否是集合类型
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
bool IsList(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;
}
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现