I want to use GetProperties
to get the properties from the parent class via the child and, despite researching this, have been unsuccessful.
I tried the next without any result:
PropertyInfo[] fields = t.GetProperties();
PropertyInfo[] fields1 = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
PropertyInfo[] propNames = t.BaseType.GetProperties( BindingFlags.Public | BindingFlags.Instance);
Just got it the properties from the child class, but dont get the properties from the parent.
Classes
public class A: B
{
public string a1 { get; set; }
public string a2 { get; set; }
public string a3 { get; set; }
public string a4 { get; set; }
}
public class B
{
public string b1;
}
Using this code I am getting A
's properties but not the property in B
.
Does this code work? Do I need to configure something in some place?