For God’s sake, don’t ever write this (at least not again). Its such a trivial piece of code that I never bother librarifying it, and yet every time I write it I leave out the reset of the stream position. But, what do you expect… I’M A MONKEY!!!
public static Object XmlSerializationCopy(Object pvValue) { if (pvValue == null) return null; XmlSerializer ser = new XmlSerializer(pvValue.GetType()); // most are probably small. MemoryStream serStream = new MemoryStream(512); using(serStream) { ser.Serialize(serStream, pvValue); serStream.Position = 0; return ser.Deserialize(serStream); } }
Trackback: KEITH