如何使用反射来确定数组的嵌套类型(元素类型)?
问题描述:
我有一个System.Type的实例,其中“IsArray”返回true。如何使用反射来确定数组的嵌套类型(元素类型)?
如何确定数组类型的“嵌套类型”?
即
Type GetArrayType(Type t)
{
if(t.IsArray)
{
// What to put here?
}
throw new Exception("Type is not an array");
}
Assert.That(GetArrayType(typeof(string[])), Iz.EqualTo(typeof(string));
Assert.That(GetArrayType(typeof(Foo[])), Iz.EqualTo(typeof(Foo));
优秀!谢谢! – 2009-05-08 17:16:24
我希望取悦:)。 – swilliams 2009-05-08 17:17:43