我已经尝试了很长时间来创建一个XML文档来保存一个大的列表以及一个'长度'和'身高'与我正在制作的关卡编辑器一起使用。
以下是用于序列化的类
[Serializable]
public class Save
{
public List<int>[,] grid { get; set; }
public int length { get; set; }
public int height { get; set; }
}
以下是单击按钮保存时发生的情况
if (keybstate.IsKeyDown(Keys.O))
{
savegame = new Save();
savegame.grid = new List<int>[length, height]; //length and height are part of the main class, and determine how big the grid class will be, as well as how big the editor area is.
savegame.grid = grid; //this grid is part of the main class. It is used to control what has been placed in the editor.
savegame.length = length;
savegame.height = height;
SerializeToXML(savegame);
}
这是&#39; serializetoXML&#39;类
static public void SerializeToXML(Save save)
{
XmlSerializer serializer = new XmlSerializer(typeof(Save));
TextWriter textWriter = new StreamWriter("save.xml");
serializer.Serialize(textWriter, save);
textWriter.Close();
}
每当我尝试运行血清化过程时,如果包含该列表,我会收到以下错误:
有一个错误反映了类型&#39; programname.Save&#39;。
基本上,我需要它做的就是将它写入XML,然后能够在以后加载它。
List<int>[,] grid;
...
protected override void Initialize()
{
...
grid = new List<int>[length, height];
for (int x = 0; x < length; x++)
{
for (int y = 0; y < height; y++)
{
grid[x, y] = new List<int> { 0 };
}
}
...
答案 0 :(得分:2)
如果您付出一些努力并向下钻取内部异常的嵌套树,您将看到Multidimensional arrays are not supported
的{{1}}。
如果合适,可以使用
XmlSerializer
代替。