Reputation: 9926
this is some class
public class ClassA
{
public string Name { get; set; }
public string Color { get; set; }
public ClassB ClassB_ { get; set; }
public class ClassB
{
public string Name { get; set; }
public float Age { get; set; }
}
}
Now, i want to print to console all the public properties of ClassA so i using this
( obj is some parameter that the method gets and print out all his properties )
var allProp = obj.GetType().GetProperties();
But when my application sees the ClassB object of ClassA - i want to print out also all the ClassB properties - and i don't know how can i know in run time that ClassB is class and not primitive object and how in run time i can print out all ClassB properties ?
Upvotes: 1
Views: 150
Reputation: 5421
Try this code:
Type type = Type.GetType("ClassA+ClassB");
var allProp = type.GetProperties();
If you need dynamic name of type try to use next code:
string fullname = typeof(ClassA.ClassB).FullName;
Upvotes: 2