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.

Welbog
  • 59,154
  • 9
  • 110
  • 123
NileshChauhan
  • 5,469
  • 2
  • 29
  • 43
  • Well, what values do you get from the two different approaches? And what is the specific control? – Marc Gravell May 29 '09 at 12:18
  • 1
    Perhaps more importantly; where did you get the PropertyDescriptor from? There are different ways of doing this that may give different results... – Marc Gravell May 29 '09 at 12:20

1 Answers1

1

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
  • 21,497
  • 7
  • 62
  • 96