Salut mobscene,
Le framework .net te propose 2 classe pour la sérilisation- SoapFormatter -> formalisme Soap Xml
- BinaryFormatter
la classse SoapFormatter se trouve dans l'espace de nom System.Runtime.Serialization.Formatters.Soap
Exemple de sérialisation:
1 2 3 4 5 6 7 8 9 10
| public class Controler {
public static void SaveO(string filename, Object o)
{
FileStream fs = new FileStream (filename, FileMode.create)
SoapFormatter sf = new SoapFormatter();
sf.Serialize(fs, o)
fs.Close();
}
} |
1 2 3 4 5 6
|
Employe ROmain = new Employe();
ROmain.nom = "toto";
ROmain.Age = 22;
Controler.SaveO("Romain.ser", ROmain) |
La désérialisation d'un objet
1 2 3 4 5 6 7 8
| public static Object LoadO(string filename) {
FileStream fs = new FileStream(filename, FileMode.Open);
SoapFormatter sf = new SoapFormatter();
Object o = sf.Deserialize(fs);
fs.Close();
return o;
} |
Pour récuperer une instance sérialiser de notre classe Employé il faut faire :
Employe ROmain2 = (Employe)Controler.LoadO("Romain.ser");
Voila j'espere que ca va t'aidé
Partager