Problem with ICloneable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    Problem with ICloneable

    I am trying to make a deep copy by adding a clone property to my class.

    Code:
    Public Class MyClass
        Implements ICloneable
        Public Property Foo as String
        Public Property Poo as MyOtherClass
        Public Function Clone() as Object Implements System.ICloneable.Clone
              Return new MyClass With {.Foo = Foo, .Poo = Poo.Clone}
        End Function
    End Class
    
    Public Class MyOtherClass
        Implements ICloneable
        Public Property FooYoung as Byte()
        Public Property Cookie as String
        Public Function Clone() as Object Implements System.ICloneable.Clone
             Return New MyOtherClass With {.FooYoung = FooYoung, .Cookie = Cookie}
        End Function
    End Class
    My Problem is that the properties of MyOtherClass do not copy even though the properties of MyClass do copy properly.
    What am I missing?
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    Ok - found the issue (after only 2 stinking hours) and it was my own stupid fault. One of the assignments I made was .foo = .foo instead of .foo = foo - the extra dot in front of foo so I was copying the empty property...
    Doh!

    Comment

    Working...