创建DTO克隆的最佳方法是什么?Silverlight中没有ICloneable接口或BinaryFormatter类.反思是唯一的方法吗?
这是我们为克隆提出的代码.这适用于Silverlight 2和3.
Public Shared Function Clone(Of T)(ByVal source As T) As T Dim serializer As New DataContractSerializer(GetType(T)) Using ms As New MemoryStream serializer.WriteObject(ms, source) ms.Seek(0, SeekOrigin.Begin) Return DirectCast(serializer.ReadObject(ms), T) End Using End Function