D
David
I have a class that whose properties include an object.
How can I read the sub object's property?
public class SubClass{
public int Number;
}
public class BigClass{
public SubClass subClass = new SubClass();
BigClass(){
subClass.Number = 10;
}
}
I tried..
Type t = Type.GetType("BigClass");
BigClass b = new BigClass();
PropertyInfo a = t.GetProperty("subClass.Number");
//at this point a is a null reference. I know I can do
PropertyInfo a = t.GetProperty("subClass");
and then use .GetValue to read the subclass's property, but without going
into detail, that will mean I'd have to
SubClass b = (SubClass)a.GetValue(b.subClass);
The problem is, at run time, I won't know that the type is SubClass. Is
there a way to find that out and execute a line like that above using
System.Reflection?
Sorry, it's late and my brain is scrambled.
How can I read the sub object's property?
public class SubClass{
public int Number;
}
public class BigClass{
public SubClass subClass = new SubClass();
BigClass(){
subClass.Number = 10;
}
}
I tried..
Type t = Type.GetType("BigClass");
BigClass b = new BigClass();
PropertyInfo a = t.GetProperty("subClass.Number");
//at this point a is a null reference. I know I can do
PropertyInfo a = t.GetProperty("subClass");
and then use .GetValue to read the subclass's property, but without going
into detail, that will mean I'd have to
SubClass b = (SubClass)a.GetValue(b.subClass);
The problem is, at run time, I won't know that the type is SubClass. Is
there a way to find that out and execute a line like that above using
System.Reflection?
Sorry, it's late and my brain is scrambled.