[Débutant] Problème Sérialisation/Désérialisation
Bonjour,
Je teste la (dé)sérialisation.
Voici mon code :
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
|
{
public partial class MainPage : UserControl
{
Humain bob;
public MainPage()
{
InitializeComponent();
bob = new Humain(25, "Bob",label1);
/* serialisation */
IsolatedStorageFileStream iso = new IsolatedStorageFileStream(@"serialisation.xml", FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication());
XmlSerializer serializer = new XmlSerializer(typeof(Humain));
StringWriter sw = new StringWriter();
StreamWriter sww = new StreamWriter(iso);
serializer.Serialize(sw, bob);
sww.Write(sw.ToString());
sww.Close();
sw.Close();
}
}
[XmlRootAttribute("Humain", Namespace="", IsNullable = false)]
public class Humain
{
int age;
string nom;
Label lbl;
public Humain()
{
this.age = 1000;
this.nom = "John Doe";
this.lbl = null;
}
public Humain(int a, string n, Label l)
{
this.age = a;
this.nom = n;
this.lbl = l;
}
public void parle()
{
this.lbl.Content = "Je suis " + this.nom + " et j'ai " + this.age.ToString() + " ans !";
}
} |
Le problème, c'est que le fichier xml contient uniquement :
Code:
1 2 3
|
<?xml version="1.0" encoding="utf-16"?>
<Humain xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> |
Ce qui n'est pas vraiment mon objet... :?
J'ai du loupé, ou mal comprendre quelque chose.
Merci pour votre aide.