rimworld-animation-studio/Assets/Scripts/Utilities/XmlUtility.cs
2022-09-21 16:15:25 -05:00

37 lines
1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;
namespace RimWorldAnimationStudio
{
public static class XmlUtility
{
public static T ReadXML<T>(string path)
{
using (StreamReader stringReader = new StreamReader(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(stringReader);
}
}
public static void WriteXML<T>(T obj, string path)
{
if (obj == null || path == null || path == "")
{ return; }
XmlSerializer writer = new XmlSerializer(typeof(T));
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
nameSpaces.Add("", "");
FileStream file = File.Create(path);
writer.Serialize(file, obj, nameSpaces);
file.Close();
}
}
}