我有以下情形:如何通过反射从类中发现基类基类?
public class BaseEntity {
public int Id { get; set; }
}
public class BaseAcademicEntity : BaseEntity { ... }
public class BaseFinancialEntity : BaseEntity { ... }
public class Student : BaseAcademicEntity {
public string Name { get; set; }
public Grade CurrentGrade { get; set; }
}
public class Grade : BaseAcademicEntity {
public string Description { get; set; }
}
好了,现在我会通过反思发现从学生类的属性。
foreach (PropertyInfo property in typeof(Student).GetProperties()) {
// Here I can discover the type of the current property.
var type = property.PropertyType;
// now, how to discover if this property is from BaseEntity type?
}
就像我在评论中写的,如何发现属性是否来自BaseEntity类型?谢谢!
谢谢。它像一个魅力! – Kiwanax