我有下面的類:加載對象數據
[Serializable]
public class SerialAssassin
{
public Hero hero;
public Point heroPB;
public Boss boss;
public Point bossPB;
public Attack attack;
public Point attackPB;
public HPMeter bossHP;
public Point bossHPPB;
public PPMeter heroPP;
public Point heroPPPB;
public Rectangle bossRect;
public Rectangle attackRect;
public int heroState;
public int stepRate;
public int attackDirection;
public int attackLoop;
public int contadorPaso;
public int contadorPasoBoss;
public int bossTop, bossLeft;
public int bossState;
public int bossHealth;
public int bossHPCap;
public int opa;
public int battlesWon;
public int mainBossCounter;
public int ppleft;
public bool paso;
public bool inStadium;
public bool fading;
public bool fightingMainBoss;
public bool fainted;
public string currentPokemon;
}
我有問題讀取來自XML,這是作爲數據寫入如下:
XmlSerializer serializer = new XmlSerializer(typeof(SerialAssassin));
TextWriter textWriter = new StreamWriter(@"..\..\Resources\saveState.xml");
serializer.Serialize(textWriter, serial);
textWriter.Close();
從那裏,我不太清楚如何讀取數據。再加上XML不會序列化Hero,Boss,Attack,HPMeter,PPMeter的對象。
public class Hero
{
int state = 0;
int x, y;
string path;
Image img;
//methods
}
我會很感激,如果你會這麼好心給我解釋如何加載這些對象/圖元,然後使用它們:
英雄職業。
未序列化的對象是否具有[Serializable]屬性? –
如果你還沒有收到答案,你期望不要發佈另一個[問題](http://stackoverflow.com/questions/13870879/serialize-a-form-along-with-all-its-data-in-c -尖銳)。嘗試以某種方式更新您之前的某個人可以按預期回答它。 – rae1
@MattiasJosefsson是的,它們是可序列化的,但它們只是保存文件中的 或 。 –