我有一个通用的包装类,有时会将数组类型作为其泛型参数。通过IsArray属性,我可以判断提供的泛型类型是否为数组。但是,在代码中,有没有一种方式可以获取数组元素的类型呢?我查看了Type对象的所有公开属性,但并没有发现相关信息。
示例:
public class wrap<T>
{
public void doSomething()
{
if (typeof(T).IsArray)
Type arrayElementType = typeof(T).??? ;
}
}
// typeof(T) when an array is "int[]"
// typeof(T).BaseType is "System.Array"
// how to get "int" out of this?