反射代碼如下收益:是解析獲取成員類型的唯一方法嗎?
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; }
}
}