//把object序列化成xml字符串
public string Serialize(Type type,Object o)
{
MemoryStream ms = new MemoryStream();
XmlSerializer xmlserializer = new XmlSerializer(type);
xmlserializer.Serialize(ms, o);
StreamReader reader = new StreamReader(ms);
return reader.ReadToEnd();
}
//把xml字符串反序列化成object
public Object Deserialize(Type type, string xmlstr)
{
byte[] xmlArray = System.Text.Encoding.UTF8.GetBytes(xmlstr);
MemoryStream ms = new MemoryStream(xmlArray);
XmlSerializer xmlserializer = new XmlSerializer(type);
return xmlserializer.Deserialize(ms);
}
65 queries in 1.784 seconds |