jet*_*hro 8 c# generics reflection
我很好奇如何检查给定类型是否为打开类型的封闭版本.例如
public bool IsGenericList(Type source)
{
return (source.IsGenericType &&
/*here goes the manipulation on source type*/ == typeof(List<>));
}
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 14
试试Type.GetGenericTypeDefinition:
public bool IsGenericList(Type source)
{
return source.IsGenericType &&
source.GetGenericTypeDefinition() == typeof(List<>);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
684 次 |
| 最近记录: |