views:

71

answers:

1

I have a control, hosted on DesignSurface.

When its Location property is accessed by control.Location, and when it's accessed by propertyDescriptor.GetValue(control), I get different values.

propertyDescriptor is of type PropertyDescriptor.

Does anyone have a solution to this? I have checked that the object instance is the same.

+1  A: 

Well it might depend on the object. and how you got your type descriptor. E.g. it could be a custom descriptor which could return what ever. If that's the case you can give the GetTypedescriptor method information of not to use custom typedescriptors. (sry for not posting the actual code but I don't have an IDE available and can't remember the exact syntax).

A different approach would be to ue a PropertyInfo instead of a propertyDescriptor (if the rest of the code works with a System.Reflection.PropertyInfo).

You can get the PropertyInfo of the Property Length for the stype string like this

typeof(string).GetProperty("Length"); or if it's an type unknown at compile time like this: obj.GetType().GetProperty("Length");

if you need to loop through all properties call GetProperties instead.

But all that PropertyInfo relies on my guess that you'd be able to use PropertyInfo instead of PropertyDescriptor

Rune FS
Or better yet... since it is known to be a Control... why not just cast it to Control and use .Location ;-p
Marc Gravell