Re: Clone a generic class in a compact framework solution...
- From: "Ginny Caughey [MVP]" <ginny.caughey.online@xxxxxxxxxxxxxx>
- Date: Wed, 3 Oct 2007 11:34:31 -0400
Andrew,
The CF has no BinaryFormatter class out of the box, although I believe there are 3rd party products that provide this capability.
--
Ginny Caughey
Device Application Development MVP
"Andrew Brook" <ykoorb@xxxxxxxxxxx> wrote in message news:eVKtfFdBIHA.3716@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
does something like the following not work?
Public Class ObjectCloner
Public Shared Function Clone(obj As Object) As Object
Dim buffer As New MemoryStream()
Dim formatter As New BinaryFormatter()
formatter.Serialize(buffer, obj)
buffer.Position = 0
Return formatter.Deserialize(buffer)
End Function
End Class
Apologies if it errors or doesn't work, I haven't tested it :)
ta,
Andrew
"Mobileboy36" <Mobileboy36@xxxxxxxxx> wrote in message news:4703766c$0$22305$ba620e4c@xxxxxxxxxxxxxxxxxHello 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/showpost.aspx?pageindex=2&siteid=1&postid=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
.
- Follow-Ups:
- Re: Clone a generic class in a compact framework solution...
- From: Andrew Brook
- Re: Clone a generic class in a compact framework solution...
- References:
- Clone a generic class in a compact framework solution...
- From: Mobileboy36
- Re: Clone a generic class in a compact framework solution...
- From: Andrew Brook
- Clone a generic class in a compact framework solution...
- Prev by Date: Re: Clone a generic class in a compact framework solution...
- Next by Date: Re: Getting starting - Windows Mobile 5.1
- Previous by thread: Re: Clone a generic class in a compact framework solution...
- Next by thread: Re: Clone a generic class in a compact framework solution...
- Index(es):
Relevant Pages
|