Wednesday, June 03, 2009 #

Hunt the Class

Popquiz - in which .NET assembly is System.Drawing.Design.UITypeEditor?

1) System.Design
2) System.Windows.Forms
3) System.ComponentModel
4) System.Drawing
5) System.Drawing.Design

A little background to help you choose:

When you want to make a property of a custom type editable via a modal dialog from within a PropertyGrid control (from the System.Windows.Forms assembly), you need to decorate the type with an EditorAttribute (from the System.ComponentModel assembly), to which you must pass the type of a class that inherits from UITypeEditor.

Your UITypeEditor class must use the IWindowsFormsEditorService (again, from the System.Windows.Forms assembly, but located in the System.Windows.Forms.Design namespace) so that it may supply a WinForms Form object (System.Windows.Forms again) to display the edit UI.

The answer? In their infinite wisdom, the .NET elves hid UITypeEditor in the System.Drawing.Design namespace to begin with - but then decided not to put it in the System.Drawing.Design assembly (oh no, that is for concrete implementations of type editors). They didn't put it in System.ComponentModel, where the EditorAttribute lives; nor in System.Windows.Forms, where it could sit beside the components upon which it relies to provide the UI services it offers (and the PropertyGrid control to which it is subservient). No, the pin-the-class-on-the-assembly game in the WinForms dev team office that Friday afternoon landed on:

System.Drawing, of course.

With all the GDI+ library tools for pushing pixels around.

A natural fit, clearly. I can't imagine why I didn't think to look there sooner.


posted @ Wednesday, June 03, 2009 10:01 PM | Feedback (2)