- Serialize the original object to XML
- Deserialize the XML back to a new object
- Cast the new (cloned) object to the type of the original object
T original;
string xmlCloned;
XmlSerializer xs = new XmlSerializer(original.GetType());
using (StringWriter writer = new StringWriter())
{
xs.Serialize(writer, original);
xmlCloned= writer.ToString();
}
StringReader sr = new StringReader(xmlCloned);
xs = new XmlSerializer(original.GetType());
T cloned = (T)xs.Deserialize(sr);