我在这里只是简单地提出这个问题,所以这个例子对现实世界没有任何意义。
public class BusinessEntity<T>
{
public int Id {get; set;}
}
public class Customer : BusinessEntity<Customer>
{
public string FirstName { get; set;}
public string LastName { get; set;}
}
当我尝试通过反射获取客户类属性时,我无法获取通用基类的属性。如何从 BusinessEntity 获取 ID?
Type type = typeof(Customer);
PropertyInfo[] properties = type.GetProperties();
// Just FirstName and LastName listed here. I also need Id here