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
| public static void BinarySerialization(object o, string file)
{
try
{
Stream stream = File.Open(file, FileMode.OpenOrCreate);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
b.Serialize(stream, o);
stream.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static object BinaryDeSerialization(string file)
{
try
{
Object o = new Object();
Stream stream = File.Open(file, FileMode.Open);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
o = b.Deserialize(stream);
stream.Close();
return o;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
} |
Partager