M
Mobileboy36
Hello Group,
How do I take a clone of a generic class in Compact Framework?
Let's say I want to clone a sorted list: SortedList As SortedList(Of
Integer, Customer)
I constructed a class like this:
Public Class ClonableAndSortedCustomerList
Inherits SortedList(Of Integer, Customer)
Public Function Clone() As ClonableAndSortedCustomerList
Return DirectCast(Me.MemberwiseClone,
ClonableAndSortedCustomerList)
End Function
End Class
Using clone method realy cloned the list, but the items in the list where
not cloned.
Changing an item in the orininal list, caused the same change in the
'cloned' list.
So: my conclusion: I need another (correct) way to clone my generic class.
In the full framework it can be realised at this way:
(http://forums.microsoft.com/msdn/sh...tid=2208691&sb=0&d=1&at=7&ft=11&tf=0&pageid=1)
Public Class ObjectCloner
Public Shared Function Clone(Of T)(obj As T) As T
Using buffer As New MemoryStream()
Dim formatter As New BinaryFormatter()
formatter.Serialize(buffer, obj)
buffer.Position = 0
Dim temp As T = DirectCast(formatter.Deserialize(buffer), T)
Return temp
End Using
End Function
End Class
But how to realise it in VB.NET, using a compact framework solution?
Best regards,
Mobile boy
How do I take a clone of a generic class in Compact Framework?
Let's say I want to clone a sorted list: SortedList As SortedList(Of
Integer, Customer)
I constructed a class like this:
Public Class ClonableAndSortedCustomerList
Inherits SortedList(Of Integer, Customer)
Public Function Clone() As ClonableAndSortedCustomerList
Return DirectCast(Me.MemberwiseClone,
ClonableAndSortedCustomerList)
End Function
End Class
Using clone method realy cloned the list, but the items in the list where
not cloned.
Changing an item in the orininal list, caused the same change in the
'cloned' list.
So: my conclusion: I need another (correct) way to clone my generic class.
In the full framework it can be realised at this way:
(http://forums.microsoft.com/msdn/sh...tid=2208691&sb=0&d=1&at=7&ft=11&tf=0&pageid=1)
Public Class ObjectCloner
Public Shared Function Clone(Of T)(obj As T) As T
Using buffer As New MemoryStream()
Dim formatter As New BinaryFormatter()
formatter.Serialize(buffer, obj)
buffer.Position = 0
Dim temp As T = DirectCast(formatter.Deserialize(buffer), T)
Return temp
End Using
End Function
End Class
But how to realise it in VB.NET, using a compact framework solution?
Best regards,
Mobile boy