So for example:
class GrandParent {
public int GrandProperty1 { get; set; }
public int GrandProperty2 { get; set; }
}
class Parent : GrandParent {
public int ParentProperty1 { get; set; }
public int ParentProperty2 { get; set; }
protected int ParentPropertyProtected1 { get; set; }
}
class Child : Parent {
public int ChildProperty1 { get; set; }
public int ChildProperty2 { get; set; }
protected int ChildPropertyProtected1 { get; set; }
}
but when i do this:
public String GetProperties() {
String result = "";
Child child = new Child();
Type type = child.GetType();
PropertyInfo[] pi = type.GetProperties();
foreach (PropertyInfo prop in pi) {
result += prop.Name + "\n";
}
return result;
}
the function returns
ChildProperty1
ChildProperty2
ParentProperty1
ParentProperty2
GrandProperty1
GrandProperty2
but I just need the properties up to the Parent class
ChildProperty1
ChildProperty2
ParentProperty1
ParentProperty2
Is there any possible way which we could specify how many levels of heirarchy could be used so the result returned would be as desired? Thanks in advance.