Problem with persisting interface collection at design time in winforms, .net
- by Jules
The easiest way to explain this problem is to show you some code:
Public Interface IAmAnnoyed
End Interface
Public Class IAmAnnoyedCollection
Inherits ObjectModel.Collection(Of IAmAnnoyed)
End Class
Public Class Anger
Implements IAmAnnoyed
End Class
Public Class MyButton
Inherits Button
Private _Annoyance As IAmAnnoyedCollection
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Annoyance() As IAmAnnoyedCollection
Get
Return _Annoyance
End Get
End Property
Private _InternalAnger As Anger
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property InternalAnger() As Anger
Get
Return Me._InternalAnger
End Get
End Property
Public Sub New()
Me._Annoyance = New IAmAnnoyedCollection
Me._InternalAnger = New Anger
Me._Annoyance.Add(Me._InternalAnger)
End Sub
End Class
And this is the code that the designer generates:
Private Sub InitializeComponent()
Dim Anger1 As Anger = New Anger
Me.MyButton1 = New MyButton
'
'MyButton1
'
Me.MyButton1.Annoyance.Add(Anger1)
// Should be: Me.MyButton1.Annoyance.Add(Me.MyButton1.InternalAnger)
'
'Form1
'
Me.Controls.Add(Me.MyButton1)
End Sub
I've added a comment to the above to show how the code should have been generated.
Now, if I dispense with the interface and just have a collection of Anger, then it persists correctly.
Any ideas?