Answer:
According to Wikipedia serialization is the process of converting a objects into a format (sequence of bytes) that can be stored in a file, a memory, or transmitted across a network.
Solution in .NET is to utilize BinaryFormatter class from System.Runtime.Serialization.Formatters.Binary namespace (mscorlib.dll assembly) and Generics.
BinaryFormatter class implement IFormatter interface (inherited by the IRemotingFormatter) to support serialization of a graph of objects.
Include references to:
and for deserialization:
According to Wikipedia serialization is the process of converting a objects into a format (sequence of bytes) that can be stored in a file, a memory, or transmitted across a network.
Solution in .NET is to utilize BinaryFormatter class from System.Runtime.Serialization.Formatters.Binary namespace (mscorlib.dll assembly) and Generics.
BinaryFormatter class implement IFormatter interface (inherited by the IRemotingFormatter) to support serialization of a graph of objects.
Include references to:
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
void BinarySerialize<T>(string file, T target)
{
FileStream fs = new FileStream(file, FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, target);
fs.Close();
}
and for deserialization:
T BinaryDeSerialize<T>(string file)
{
FileStream fs = new FileStream(file, FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
T result = (T)formatter.Deserialize(fs);
fs.Close();
return result;
}