Reflection problem

  • Thread starter Thread starter scoffer
  • Start date Start date
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??
 
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.
 
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.
 
Back
Top