我很好奇如何检查给定类型是否已关闭打开类型的版本。例如
public bool IsGenericList(Type source)
{
return (source.IsGenericType &&
/*here goes the manipulation on source type*/ == typeof(List<>));
}
答案 0 :(得分:14)
尝试Type.GetGenericTypeDefinition
:
public bool IsGenericList(Type source)
{
return source.IsGenericType &&
source.GetGenericTypeDefinition() == typeof(List<>);
}