0
我試圖XML序列化一個類的對象,但具有下列問題:C#XML序列化錯誤
代碼編譯罰款,並在MessageBox顯示所有正確的數據,但是當我查看XML它似乎不包括實際傳輸的數據(即FireGridLocation數據)從XML中丟失。
XmlSerializer s;
StringWriter w;
FireGridUnit fireGridUnit = new FireGridUnit();
fireGridUnit.FireGridLocation = new GridUnit(GridLock.getColumn, GridLock.getRow);
MessageBox.Show("gridlock col " + GridLock.getColumn);
MessageBox.Show("column fire " + fireGridUnit.FireGridLocation.getColumn);
MessageBox.Show("row fire " + fireGridUnit.FireGridLocation.getRow);
s = new XmlSerializer(typeof(FireGridUnit));
w = new StringWriter();
s.Serialize(w, fireGridUnit);
MessageBox.Show(w.ToString());
alt text http://img52.imageshack.us/img52/220/errorce.jpg
這裏是FireGridUnit:
[Serializable]
public class FireGridUnit
{
/// <summary>
/// Location storage
/// </summary>
//public GridUnit FireGridLocation { get; set; }
public GridUnit FireGridLocation;
}
這裏是GridUnit類:
public class GridUnit
{
/// <summary>
/// Default initialization
/// </summary>
public GridUnit()
{
Column = -1;
Row = -1;
}
/// <summary>
/// Initialize to supplied coordinate
/// </summary>
/// <param name="column"></param>
/// <param name="row"></param>
public GridUnit(int column, int row)
{
Column = column;
Row = row;
}
/// <summary>
/// Set/Return Column
/// </summary>
//public int Column { get; set; }
private int Column;
public int getColumn
{
get { return Column; }
}
/// <summary>
/// Set/Return Row
/// </summary>
//public int Row { get; set; }
private int Row;
public int getRow
{
get { return Row; }
}
}
,如果你可以用這個問題的幫助,你的投入非常歡迎。
是即時通訊新的這一點,但跟蹤這個問題到我的報道。這是很有用的知識,知識。謝謝。 – iTEgg 2010-06-04 00:26:03