views:

51

answers:

0

I have a custom WinForms designer, and I've just added functionality to create duplicate components using drag & drop (with the ctrl key held down) by inheriting from CodeDomDesignerLoader. Unfortunately, this works a little too well: the new components get all of the same property values as their originals, and I need some of those to be unique (they're read-only and will get filled with a proper value upon save).

I'm looking for an attribute or similar to flag those properties' values not to be copied, or perhaps a way for the Service to look for particular property names to skip.

Update:

I've found a solution that, while horrendously unclean, appears to work for the time being. For each property I don't want to be copied, I've added a private boolean field:

Private _ResetMyProperty1 As Boolean = False
Private _ResetMyProperty2 As Boolean = False

I then extend New() before the InitializeComponent() call with the following:

    For Each frame As StackFrame In New StackTrace(1).GetFrames()
        If frame.GetMethod().DeclaringType Is GetType(System.Windows.Forms.Design.ParentControlDesigner) AndAlso frame.GetMethod().Name = "OnDragDrop" Then
            _ResetMyProperty1 = True
            _ResetMyProperty2 = True

            Exit For
        End If
    Next

And finally, the property setter extended, like so:

Public Property MyProperty1() As Integer
    Get
        Return _MyProperty1
    End Get
    Set(ByVal Value As Integer)
        If Not _ResetMyProperty1 Then
            _MyProperty1 = Value
        Else
            _MyProperty1 = 0

            _ResetMyProperty1 = False
        End If
    End Set
End Property