我有一个类叫做GamePrototype,我想序列化XML的使用,包括下列成员:如何序列化一个包含XML队列的类?
public class GamePrototype
{
private string mPath;
private bool[] isHumanPlayer;
private Queue<CardPrototype> mKickStack;
private Queue<CardPrototype> mMainDeck;
private Queue<CardPrototype> mStarterDecks;
private Queue<CardPrototype> mSuperVillianStack;
private Queue<CardPrototype> mWeaknessStack;
private Queue<PlayerHero> mPlayableHeroes;
public Queue<CardPrototype>[] mStartingLocations;
}
我一直在试图用这种方法序列化类数据。 “这”指的是上面提到的类的实例:
public void XMLShelf(string path)
{
XmlSerializer boxPacker = new XmlSerializer(typeof(GamePrototype));
StreamWriter boxPlacer = new StreamWriter(path);
boxPacker.Serialize(boxPlacer, this);
boxPlacer.Close();
}
我有getter和setter大多数如果不是所有的人,但我发现了两个错误,我不知道如何避免:
Exception:Thrown: "You must implement a default accessor on
System.Collections.Generic.Queue`1[[Cards.GameBuilding.CardPrototype, Cards,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it inherits from
ICollection."...
和
Exception:Thrown: "There was an error reflecting type
'Cards.GameBuilding.GamePrototype'." (System.InvalidOperationException)
我在其他职位,在当前的形势下,这个类是因为队列不可序列读取。这些信息可能已过时?我不知道,但我的问题是:
有没有一种方法可以轻松地将这些队列转移到列表只是为了序列化? 我需要为这些成员所属的所有班级做到这一点吗?例如,卡原型包含一个队列和一个堆栈。
非常感谢您为我提供的任何帮助。
[Queue](http://msdn.microsoft.com/en-us/library/7977ey2c%28v=vs.110%29.aspx)有Serializable属性,所以我不认为这是原因你不能序列化。请添加你拥有的代码(你写道,你有他们的属性,任何属性?),例外,你使用什么样的序列化和你如何序列化。 –
Reniuz
2014-11-24 12:33:15
错误请 - 确切,不“喜欢”。 – TomTom 2014-11-24 12:35:57
我更新了我的帖子,并添加了我在调试过程中注意到的第二个异常。 – gheist 2014-11-24 15:24:18