Fooker
Fooker

Reputation: 796

How to get nested level of property class by reflection in .net

Class A
{
  public B child {get; set;}
}

Class B
{
   public string childProperty {get; set;}
}

I am getting all property

 var BType = AType.GetType().GetProperty("child");

I am able to get "Child" property of A, but how i can get "childProperty" from BType?

Upvotes: 0

Views: 458

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125640

You can get B type using BType.PropertyType:

A AType = new A();

var BType = AType.GetType().GetProperty("child");
var childPropertyType = BType.PropertyType.GetProperty("childProperty");

Upvotes: 1

Related Questions