我很好奇如何检查给定类型是否是开放类型的封闭版本。例如
public bool IsGenericList(Type source)
{
return (source.IsGenericType &&
/*here goes the manipulation on source type*/ == typeof(List<>));
}
最佳答案
尝试 Type.GetGenericTypeDefinition
:
public bool IsGenericList(Type source)
{
return source.IsGenericType &&
source.GetGenericTypeDefinition() == typeof(List<>);
}
关于c# - 封闭式与开放式比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3932193/