2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
2022-12-08 20:54:45 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner.Helpers
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class XmlSerializeHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string XmlSerialize<T>(T obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
|
{
|
|
|
|
|
|
Type t = obj.GetType();
|
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(obj.GetType());
|
|
|
|
|
|
serializer.Serialize(sw, obj);
|
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
return sw.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static T DESerializer<T>(string strXML) where T : class
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (StringReader sr = new StringReader(strXML))
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
|
|
|
|
|
return serializer.Deserialize(sr) as T;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
catch (Exception)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|