1: Reflection
Public t deepcopy (t obj)
{< br> Object retval = activator. createinstance (typeof (t);
propertyinfo [] Pis = typeof (t ). getproperties ();
foreach (propertyinfo PI in PIS)
{< br> try {pi. setvalue (retval, Pi. getvalue (OBJ, null), null) ;}< br> catch {}< BR >}< br> return (t) retval;
}
2. XML serialization and deserialization
Public t deepcopy <t> (t obj)
{
Object retval;
Using (memorystream MS = new memorystream ())
{
Xmlserializer xml = new xmlserializer (typeof (t ));
XML. serialize (MS, OBJ );
Ms. Seek (0, seekorigin. Begin );
Retval = xml. deserialize (MS );
Ms. Close ();
}
Return (t) retval;
}
3: implement binary serialization and deserialization
Public Static T deepcopy < T > (T obj)
{
Object Retval;
Using Memorystream MS = New Memorystream ())
{
Binaryformatter BF = New Binaryformatter ();
// Serialize to stream
BF. serialize (MS, OBJ );
Ms. Seek ( 0 , Seekorigin. Begin );
// Deserialization into objects
Retval = BF. deserialize (MS );
Ms. Close ();
}
Return (T) retval;
} 4: Using Silverlight datacontractserializer implementation, used in the Silverlight Client Public static t deepcopy <t> (t obj)
{
Object retval;
Using (memorystream MS = new memorystream ())
{
Datacontractserializer SER = new datacontractserializer (typeof (t ));
Ser. writeobject (MS, OBJ );
Ms. Seek (0, seekorigin. Begin );
Retval = Ser. readobject (MS );
Ms. Close ();
}
Return (t) retval;
}