可能重复:
How do I use reflection to determine the nested type of an array?
我有一个A类,并尝试在其中获取数组的基础类型。
Class A
{
A1[] obja1;
A2[] obja2;
string x;
int i;
}
如何将底层对象类型的obja1作为A1和obja2作为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..
答案 0 :(得分:2)