WinForms depreciates ISupportInitialize from custom control

I have a WinForms custom control that used to come from PictureBox (which implements ISupportInitialize) and I converted it to descent from Control (which does not implement ISupportInitialize).

I have two dead methods BeginInit () and EndInit () in a control with the sole purpose of not breaking the developer's existing code. The WinForms designer generates something like this:

((System.ComponentModel.ISupportInitialize)(this.helpButton1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.helpButton1)).EndInit();

      

This means that if I choose ISupportInitialize, no one even gets a compiler warning that something is wrong, it just crashes at runtime with a type conversion error (can't use HelpButton for ISupportInitialize).

Typically, to remove a deprecated property, you can mark it with [Obsolete] and [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)], or simply remove it and have everyone remove it from the designer.cs file before they can compile. But with ISupportInitialize it seems like you are stuck maintaining it forever once it is added.

I thought about using an explicit conversion in ISupportInitialize, but that doesn't work because you cannot create explicit conversions to interfaces:

public static explicit operator ISupportInitialize(HelpButton self)
{
    return new FakeISupportInitialize();
}
// gives error: user-defined conversions to or from an interface are not allowed.

      

Is there a way to remove the interface from the designer's visibility without breaking existing code?

+3


source to share





All Articles