可能重复:
如何使用反射来确定数组的嵌套类型?
我有一个 A 类并试图在其中获取数组的基础类型。
Class A
{
A1[] obja1;
A2[] obja2;
string x;
int i;
}
如何将 obj1 的底层对象类型作为 A1,将 obj2 的底层对象类型作为 A2?这是我拥有的代码的一部分:
object AClass = myAssembly.CreateInstance("A");
PropertyInfo[] pinfos = AClass.GetType().GetProperties();
foreach(PropertyInfo pinfo in pinfos)
{
if(pinfo.PropertyType.IsArray)
{
//here get the the underlying property type so that I can do something as follows
var arr = myAssembly.CreateInstance(typeof(A1), 100);
//need to get if the array is array of A1 or A2 but do not want to hardcode
}
}
Thanks for the help..