C# 比较封闭类型和开放类型

C# 比较封闭类型和开放类型,c#,reflection,generics,C#,Reflection,Generics,我很好奇如何检查给定的类型是否是开放类型的封闭版本。比如说 public bool IsGenericList(Type source) { return (source.IsGenericType && /*here goes the manipulation on source type*/ == typeof(List<>)); } public bool isgenericslist(类型源) { 返回(source.IsGe

我很好奇如何检查给定的类型是否是开放类型的封闭版本。比如说

public bool IsGenericList(Type source)
{
    return (source.IsGenericType &&
            /*here goes the manipulation on source type*/ == typeof(List<>));
}
public bool isgenericslist(类型源)
{
返回(source.IsGenericType)&&
/*下面是对源类型*/==typeof(List))的操作;
}
试试:

public bool isgenericslist(类型源)
{
返回source.IsGenericType&&
source.GetGenericTypeDefinition()==typeof(列表);
}

这是我一开始就尝试过的,但认为它不起作用,因为我在代码的其他地方有bug。无论如何,谢谢你:)
public bool IsGenericList(Type source)
{
    return source.IsGenericType &&
           source.GetGenericTypeDefinition() == typeof(List<>);
}