2023-10-11 11:51:44 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
2023-10-13 14:15:26 +09:00
|
|
|
|
namespace STcpHelper.Utility
|
2023-10-11 11:51:44 +09:00
|
|
|
|
{
|
2023-10-13 14:15:26 +09:00
|
|
|
|
public class SXmlSerializerHelper : ISSerializer
|
2023-10-11 11:51:44 +09:00
|
|
|
|
{
|
2023-10-13 14:15:26 +09:00
|
|
|
|
public string Serialize<T>(T obj)
|
2023-10-11 11:51:44 +09:00
|
|
|
|
{
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
{
|
|
|
|
|
serializer.Serialize(sw, obj);
|
|
|
|
|
return sw.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 14:15:26 +09:00
|
|
|
|
public T Deserialize<T>(string str)
|
2023-10-11 11:51:44 +09:00
|
|
|
|
{
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
|
|
|
|
using (StringReader sr = new StringReader(str))
|
|
|
|
|
{
|
|
|
|
|
return (T)serializer.Deserialize(sr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|