Search code examples
c#.netvb.netattributesuitypeeditor

From a UITypeEditor, retrieve an attribute applied to the parent of a property in .net


It's not quite as simple as the title says but I hope you understand.

Consider this scenario:

Class MyClass

    Property SubProp1
    End Property

    -TypeEditor(whatever)- 
    Property SubProp2
    End Property

End Class

Class MyButton
    Inherits Button

    -MyCustomAttribute-
    Property MC as MyClass
    End Property

End Class

Next, I put an instance of MyButton into a property grid, expand property MC and edit SubProp2.

From the type editor for SubProp2, I want to get hold of the attribute applied to property MC.

Looking at the context,PropertyDescriptor.ComponentType, we arrive at Type: MyClass. If i look at the attributes applied to MyClass, though, it will only return the attributes applied directly to MyClass, and not the extra attribute applied to the property MC.

I'm struggling to get back to MC so that I can read the attributes applied there. Anyone any ideas?

ETA:

I've answered it below:


Solution

  • Actually, further to my comment to Thomas, this is possible without late binding. Here's how:

    DirectCast(context, GridItem).Parent.PropertyDescriptor.Attributes.
    

    Voila!