reflection, access the field of object dynamically

  • Thread starter Thread starter tienhuat
  • Start date Start date
T

tienhuat

Hi,

Let say I have an instance of class, eg. ArrayList. And assume that I
don't what properties are inside this instance/class. As I know I can
use Reflection to get the properties.

Now, assume that I got the properties programmatically, let them be
Count and Capacity.

How can I access the Count and Capacity for this 'instance',?

regards,
john
 
How can I access the Count and Capacity for this 'instance',?

PropertyInfo.GetValue(yourInstance)


Mattias
 
Or, more fully:

PropertyInfo countPi = instance.GetType().GetProperty("Count");
int count = (int)countPi.GetValue(instance);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top