I have a class Cinherited which inherits from class Cbase.
When I attempt to list the properties for class Cinherited, using reflection, it only returns the properties for the base class, Cbase.
Here is the (somewhat simplified) code that demonstrates the problem:
public class Cinherited: Cbase
{
public int x;
public void printProperties()
{
Type t = this.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo prop in pi)
{
// ERROR: Next line only prints properties in base class Cbase.
Console.Write("Prop: {0}: {1}\n", prop.Name, prop.GetValue(this,null));
}
}
}
It looks like you’ve declared fields rather than properties on your derived class. You can use code like this to access them:
You can set the value of this field by calling
SetValue():