dimanche 18 septembre 2016

Recursively find a property in an object

I have a RootObject which can have multiple properties in it e.g A, B C below. RootObject is the result of an API call. It can have variable number of properties returned depending on the query used to call the API. In one call it may return A,B,C. For a different query it may return A,B,X,Y. When I get the RootObject I do not know what all properties it will have.

Now each property will have a screenshot object in it e.g. B->screenshot. Or it will have screenshot property burried under its sub property. eg. B->B1->Screenshot.

How can I get all the screenshot objects present in my RootObject? I want to get the following:

rootobject.a.s

rootobject.b.b1.s

public class RootObject
{
  A a;
  B b;
  C c;

}
public class A
{
  Screenshot S;
}
public class B
{
  B1 b1;

}
public class B1
{
  Screenshot S;
}





Aucun commentaire:

Enregistrer un commentaire