You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
1 year ago
|
using System.IO;
|
||
|
using System.Text;
|
||
|
using System.Xml;
|
||
|
using System.Xml.Serialization;
|
||
|
|
||
|
namespace SSWMS.Common
|
||
|
{
|
||
|
public class XmlConvert
|
||
|
{
|
||
|
public static T XmlDeserialize<T>(string xml)
|
||
|
{
|
||
|
using (StringReader sr = new StringReader(xml))
|
||
|
{
|
||
|
return (T)new XmlSerializer(typeof(T)).Deserialize(sr);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static string XmlSerialize<T>(T t)
|
||
|
{
|
||
|
using (MemoryStream ms = new MemoryStream())
|
||
|
{
|
||
|
new XmlSerializer(typeof(T)).Serialize(new XmlTextWriter(ms, Encoding.UTF8)
|
||
|
{
|
||
|
Formatting = Formatting.None
|
||
|
}, t, new XmlSerializerNamespaces(new XmlQualifiedName[]
|
||
|
{
|
||
|
new XmlQualifiedName("", "")
|
||
|
}));
|
||
|
ms.Position = 0;
|
||
|
using (StreamReader sr = new StreamReader(ms))
|
||
|
{
|
||
|
return sr.ReadToEnd();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|