public static Boolean Serializer(Donnee.Entity.Promotion p_Promotion) { try { XmlSerializer xs = new XmlSerializer(typeof(Donnee.Entity.Promotion)); StreamWriter wr = new StreamWriter("Promotion.xml"); xs.Serialize(wr, p_Promotion); Console.WriteLine("Ok"); return(true); } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); return(false); } }
public static void Deserializer() { try { XmlSerializer xs = new XmlSerializer(typeof(Donnee.Entity.Promotion)); using (StreamReader rd = new StreamReader("Promotion.xml")) { Donnee.Entity.Promotion p = xs.Deserialize(rd) as Donnee.Entity.Promotion; Console.WriteLine("Id : {0}", p.Id); Console.WriteLine("Année : {0}/{1}", p.Annee_dbt, p.Annee_fin); Console.WriteLine("Nombre étudiants : {0}", p.Nb_etd); } } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }