Reflection problem

S

scoffer

Hi,

i'm trying to access a property value in this way:

PropertyInfo pi = myObject.GetType().GetProperty(myPropName);

I'm sure that the object myObject have the myPropName property, but the pi
variable result nothing.

Can you help me??
 
A

Ahmed

Hi,

If you know the type of the object or the super class/interface of a
collection of objects I would do the following:

If typeof myobject is objectType then

propertyinfo pi = ctype(myObject,objectType).myPropName

end if

I hope that helps.
 
H

Herfried K. Wagner [MVP]

scoffer said:
i'm trying to access a property value in this way:

PropertyInfo pi = myObject.GetType().GetProperty(myPropName);

I'm sure that the object myObject have the myPropName property, but the pi
variable result nothing.

Check out the overloaded verisons of 'GetProperty', especially those which
accept 'BindingFlags'. Specify 'BindingFlags.Instance' and appropriate
binding flags for the accessibility of the property.
 

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

Top