反射代码如下收益:是解析获取成员类型的唯一方法吗?
System.Collections.Generic.IList`1[TestReflection.Car] Cars
我怎样才能获得通过反射Cars
根型?不是IList<Car>
- 我怎样才能得到Car
?
using System;
using System.Reflection;
using System.Collections.Generic;
namespace TestReflection
{
class MainClass
{
public static void Main(string[] args)
{
Type t = typeof(Dealer);
MemberInfo[] mi = t.GetMember("Cars");
Console.WriteLine("{0}", mi[0].ToString());
Console.ReadLine();
}
}
class Dealer
{
public IList<Car> Cars { get; set; }
}
class Car
{
public string CarModel { get; set; }
}
}