111,120
社区成员
发帖
与我相关
我的任务
分享
public static string SerializeToXml(object srcObject, Type type)
{
type = type != null ? type : srcObject.GetType();
XmlSerializer xs = new XmlSerializer(type);
StringBuilder stb = new StringBuilder();
XmlWriter xw = XmlWriter.Create(stb);
xs.Serialize(xw, srcObject);
return stb.ToString();
}
public static string SerializeToXml(object srcObject, Type type)
{
type = type != null ? type : srcObject.GetType();
XmlSerializer xs = new XmlSerializer(type);
StringBuilder stb = new StringBuilder();
XmlWriter xw = XmlWriter.Create(stb, new XmlWriterSettings(){Encoding = UTF8Encoding.UTF8});
xs.Serialize(xw, srcObject);
return stb.ToString();
}