views:

16

answers:

0

I have a requirement to persist a collection at design-time:

Public Class MyButton
    Inherits Button

    Private _MyCol As MyCol
    <Editor(GetType(MyColEditor), GetType(UITypeEditor))> _
    Public Property MyCol() As MyCol
        Get
            Return _MyCol
        End Get
        Set(ByVal value As MyCol)
            _MyCol = value
        End Set
    End Property

End Class 

For the purposes of this question, MyCol is a simple class that inherits from ObjectModel.Collection(Of Integer).

Now, in the editor (MyColEditor), the collection can either be created and maintained, or MyCol can point to an existing collection from somewhere else (for instance in another control).

For this reason, MyCol cannot be readonly and cannot be decorated with DesignerSerializationVisibility.Content.

If I ask the MyCol to point to another collection, I get this in InitializeComponent:

New zSerializeCollection.MyCol.Add(0) // Partial line generated
New zSerializeCollection.MyCol.Add(0) // Partial line generated
Me.MyButton1.MyCol = Me.MyColProvider1.MyCol // Correct, I only want this.

(MyColProvider1 is another control or component with a ReadOnly MyCol property.)

I can fix this by wrapping the MyCol class in a new MyColSet class that contains a ReadOnly MyCol property that is decorated with the DesignerSerializationVisibility.Content attribute:

Public Class MyColSet

    Private _MyCol As MyCol = New MyCOl
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public ReadOnly Property MyCol() As MyCol
        Get
            Return Me._MyCol
        End Get
    End Property

End Class

Then, in MyButton and MyColProvider, I change the MyCol types to MyColSet.

Is there another way?