Re: Clone a generic class in a compact framework solution...
- From: "Andrew Brook" <ykoorb@xxxxxxxxxxx>
- Date: Thu, 4 Oct 2007 08:36:39 +0100
hehe, ok, I guess that would cause problems then. How about implementing
IClonable on all the custom classes and making sure it doesn't do a
'shallow' copy of any member variables?
Andrew
"Ginny Caughey [MVP]" <ginny.caughey.online@xxxxxxxxxxxxxx> wrote in message
news:5C3BA6C6-11DC-4DB7-82BA-617D17D1BA86@xxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxx
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/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: Ginny Caughey [MVP]
- 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
- Re: Clone a generic class in a compact framework solution...
- From: Ginny Caughey [MVP]
- Clone a generic class in a compact framework solution...
- Prev by Date: Windows Mobile 5.0 Virtual Keyboard Customization
- Next by Date: Modify sdf database on a desktop application
- 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
|