I am simplyfing the question here, so the example could not make any sence for the real world.
public class BusinessEntity<T>
{
public int Id {get; set;}
}
public class Customer : BusinessEntity<Customer>
{
public string FirstName { get; set;}
public string LastName { get; set;}
}
When I try to get Customer class properties by reflection, I could not get the properties of the generic base class. How to get Id from the BusinessEntity ?
Type type = typeof(Customer);
PropertyInfo[] properties = type.GetProperties();
// Just FirstName and LastName listed here. I also need Id here
Nope, that definitely returns all 3 properties. Check that in your real code, whether
Idisinternal/protected/ etc (i.e. non-public). If it is, you’ll need to pass inBindingFlags, for example:(the default is public + instance + static)
Also check that it isn’t a field in your actual code; if it is:
then it is a field, and you should
usemakeGetFieldsIda property ;p