rimworld-animation-studio/Assets/Scripts/Utilities/XmlUtility.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2022-09-14 05:25:58 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;
2022-10-02 05:42:07 +00:00
using UnityEngine;
2022-09-14 05:25:58 +00:00
namespace RimWorldAnimationStudio
{
public static class XmlUtility
2022-09-14 05:25:58 +00:00
{
public static T ReadXML<T>(string path)
2022-09-14 05:25:58 +00:00
{
using (StreamReader stringReader = new StreamReader(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
2022-10-02 05:42:07 +00:00
var data = (T)serializer.Deserialize(stringReader);
2022-09-14 05:25:58 +00:00
2022-10-02 05:42:07 +00:00
return data;
2022-09-14 05:25:58 +00:00
}
}
2022-09-21 21:15:25 +00:00
public static void WriteXML<T>(T obj, string path)
2022-09-14 05:25:58 +00:00
{
2022-09-21 21:15:25 +00:00
if (obj == null || path == null || path == "")
2022-09-14 05:25:58 +00:00
{ return; }
2022-09-21 21:15:25 +00:00
XmlSerializer writer = new XmlSerializer(typeof(T));
2022-09-14 05:25:58 +00:00
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
nameSpaces.Add("", "");
FileStream file = File.Create(path);
2022-09-21 21:15:25 +00:00
writer.Serialize(file, obj, nameSpaces);
2022-09-14 05:25:58 +00:00
file.Close();
}
}
}