public static T DeserialXmlToModel<T>(string xmlDocument) { T cmdObj = default(T); XmlSerializer se = new XmlSerializer(typeof(T)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlDocument)); XmlTextReader reader = new XmlTextReader(ms); try { reader.Normalization = false; object obj = se.Deserialize(reader); if (obj != null) { cmdObj = (T)obj; } reader.Close(); ms.Close(); } catch (XmlException ex) { } catch (Exception ex) { } finally { se = null; ms.Dispose(); ms = null; reader = null; } return cmdObj; }
原文:http://www.cnblogs.com/bincoding/p/7679920.html