Friday, 26 December 2014

probleme to save object into Xml file c#



I'm trying to save a dictionary of Matrix into a Xml file. My Matrix class attributes are :



public class Matrix
{
public int Lines { get; set; }
public int Columns { get; set; }
public double[,] Elements { get; set; }
public string name { get; set; }
}


After many attempts, i wrote this :



string fileName = dlg.FileName;
Stream writer = new FileStream(fileName,FileMode.Create);

foreach (KeyValuePair<String, Matrix> matrice in CalMat.Calculatrice.listMatrix)
{
XmlSerializer x = new XmlSerializer(matrice.GetType());
x.Serialize(writer, matrice);

}
writer.Close();


If i run this code with one matrix, the file is created, but i only have this sentence written :



<?xml version="1.0"?><KeyValuePairOfStringMatrix xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" /><?xml version="1.0"?>


I think my code is missing something but I don't know what. A write method, I guess.


Thank you for your time!


No comments:

Post a Comment