jeudi 14 juillet 2016

Get a list via reflection

I have some class that contains a List with a type of PropertyInfo:

public List<PropertyInfo> Properties {get; set;}

And I have an instance of that class, but it is not known which class it is at the run-time. So with that instance, in my case it's called P, I need to loop through the upper-mentioned list. Now I can get the value of the property by using:

var PropList = P.GetType().GetProperty("Properties").GetValue(this, null)

But if I try to loop through it:

foreach (var thisProp in PropList) - I get an error.

So, is there any other way to do this?

Thanks





Aucun commentaire:

Enregistrer un commentaire