我想序列化多邊形的列表。這個類包含3個公共字段:amountOfVertexes,列出哪裏Stroke - 是我自己的類,列出哪裏Point - 是C#類。非我不能序列化它,我錯了嗎? 這是我的課如何序列化點
[XmlRoot("CustomPolygon")]
public class CustomPolygon
{
#region Cunstructors
public CustomPolygon()
{
}
#endregion
#region Public fields
[XmlAttribute("amountOfVertexes")]
public int amountOfVertexes; // Количество сторон полигона
[XmlArray("Points")]
[XmlArrayItem("Point")]
public List<Point> listOfVertexes; // Список всех вершин
[XmlArray("Strokes")]
[XmlArrayItem("Stroke")]
public List<Stroke> listOfStrokes; // Список ребер
#endregion
#region Private fields
private PointCollection Points;
#endregion
我在中風
[XmlRoot("Stroke")]
public class Stroke
{
#region Constructors
public Stroke()
{
this.beginPoint = new Point();
this.endPoint = new Point();
}
public Stroke(Point pBegin, Point pEnd)
{
this.beginPoint = pBegin;
this.endPoint = pEnd;
}
#endregion
#region Public Member Variables
[XmlAttribute("beginPoint")]
public Point beginPoint; // Начальная точка отрезка
[XmlAttribute("endPoint")]
public Point endPoint; // Конечная точка отрезка
#endregion
}
添加相同的元素,但我不能添加相同的元素(我的意思是[XmlAttribute]),以Point類,因爲它關閉。我做錯了什麼?我想這個序列碼的whitch幫助:
using (StreamWriter writer = new StreamWriter(saveFileDialogPolygon.FileName))
{
XmlSerializer xmlSerializerCustom = new XmlSerializer(typeof (List <CustomPolygon>));
xmlSerializerCustom.Serialize(writer,listOfCustomPolygons);
}
writer.Close();
而且我得到了「發生錯誤,而反射式」可能是因爲點的錯誤?那麼,我如何序列化(和desirialze)標準的Point類呢?
請註明的答案接受。如果問題是正確的解決方案,您可以接受自己的答案。 – Joel