日期:2014-05-17 浏览次数:21346 次
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
var typeA = Type.GetType("ConsoleApplication1.A");
Console.WriteLine(typeA.Name);
var propertyHead = typeA.GetProperty("Head");
if (propertyHead.PropertyType.IsGenericType) {
if (propertyHead.PropertyType.GenericTypeArguments.Length > 0) {
var typeB = propertyHead.PropertyType.GenericTypeArguments[0];
Console.WriteLine(typeB.Name);
foreach(var each in typeB.GetProperties()){
Console.WriteLine(each.Name);
}
}
}
Console.WriteLine("press any key to exit.");
Console.ReadLine();
}
}
public class A {
private List<B> head = new List<B>();
public List<B> Head {
get { return head; }
set { head = value; }
}
}
public class B {
public int Id { get; set; }
public string Name { get; set; }
}
}