problème de sérialisation
Bonjour
J'ai les classes suivante (j'ai supprimé les méthodes qui ne sont pas utilisées pour la sérialisation.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| [Serializable]
public class TOPathsContainer
{
private List<TOPath> pathsList;
public TOPathsContainer()
{
pathsList = new List<TOPath>();
TOPath.pathsList = pathsList;
}
public void save()
{
TextWriter tw = new StreamWriter("test.xml");
XmlSerializer xs = new XmlSerializer(typeof(TOPathsContainer));
xs.Serialize(tw, this);
tw.Close();
}
public List<TOPath> pPathsList
{
get
{
return pathsList;
}
set
{
pathsList = value;
}
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| public class TOPath
{
private List<TOWayPoint> wayPoints = new List<TOWayPoint>();
private int width;
private Color color;
[XmlIgnore]
public static List<TOPath> pathsList;
public TOPath(int width, Color color)
{
this.width = width;
this.color = color;
}
public TOPath() { }
[XmlAttribute("width")]
public int pWidth
{
get
{
return width;
}
set
{
width = value;
}
}
[XmlIgnore]
public Color pColor
{
get
{
return color;
}
}
[XmlAttribute("colorName")]
public string pColorName
{
get
{
return ColorTranslator.ToHtml(color);
}
set
{
color = ColorTranslator.FromHtml(value);
}
}
public List<TOWayPoint> pWayPoints
{
get
{
return wayPoints;
}
set
{
wayPoints = value;
}
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public partial class TOWayPoint : UserControl
{
private SharpMap.Geometries.Point worldPosition;
[XmlIgnore]
public const int wayPointDimension = 8;
public TOWayPoint(Point position, TOPath path)
{
InitializeComponent();
this.path = path;
worldPosition = TOPathsContainer.mapImage.Map.ImageToWorld((PointF)position);
Width = wayPointDimension;
Height = wayPointDimension;
Location = new Point(position.X - wayPointDimension / 2, position.Y - wayPointDimension / 2);
BackColor = path.pColor;
BorderStyle = BorderStyle.FixedSingle;
}
public TOWayPoint() { }
} |
En gros j'ai une classe TOPathsContainer qui contient une liste de TOPath, contenant eux-même une liste de TOWayPoint.
Le problème : lors de la sérialisation j'obtiens l'erreur suivante :
Citation:
Une erreur s'est produite lors de la réflexion du type 'Topographie3D.Views.Map.Path.TOPathsContainer'.
En regardant un peu plus loin je trouve :
Citation:
{"Une erreur s'est produite lors de la réflexion du type 'Topographie3D.Views.Map.Path.TOPath'."}
Apparemment le problème provient de la liste wayPoints, si j'ignore la propriété pWayPoints de TOPath ([XmlIgnore] public List<TOWayPoint> pWayPoints).
Je n'ai pas d'erreur et le fichier xml est générer.
Donc, comment faire pour sérialiser aussi mes objets wayPoints ? Qu'ai-je fait de faux ?