Home All Groups Group Topic Archive Search About
Author
16 May 2006 6:31 PM
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??

Author
16 May 2006 7:43 PM
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.
Author
16 May 2006 10:07 PM
Herfried K. Wagner [MVP]
"scoffer" <scof***@email.it> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>