我正在从此 xml 文件加载不同类型的路径:
<?xml version="1.0" encoding="utf-8" ?>
<SplashScreen>
<Image>
<Path>Visual/Screens/SplashScreen/samurai1024-768</Path>
<Path>Visual/Screens/SplashScreen/Humanoid1024-768</Path>
</Image>
<Song>
<Path>Audio/SplashScreen/wardrums</Path>
</Song>
</SplashScreen>
这是我用来序列化和反序列化的 XmlManager 类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace Lucid.Classes
{
public class XmlManager<T>
{
public Type Type;
public T Load(string P_path)
{
T instance;
using (TextReader reader = new StreamReader(P_path))
{
XmlSerializer xmlSerializer = new XmlSerializer(Type);
instance = (T)xmlSerializer.Deserialize(reader);
}
return instance;
}
public void Save(string P_path, object P_obj)
{
using (TextWriter writer = new StreamWriter(P_path))
{
XmlSerializer xmlSerializer = new XmlSerializer(Type);
xmlSerializer.Serialize(writer, P_obj);
}
}
}
}
这是我要反序列化的类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Lucid.Classes
{
[XmlRoot("SplashScreen")]
public class SerializableSplashScreen
{
[XmlElement("Image")]
public List<string> imgPathList { get; set; }
[XmlElement("Song")]
public List<string> songPathList { get; set; }
}
}
不知何故,它只接受图像中的第一个路径,而不记录其余部分。难道我做错了什么?