public static void SerializeToBin(this object objectGraph, FileInfo target)
{
if (target.Exists)
{
target.Delete();
}
using (var fs = target.Create())
{
var bs = new BinaryFormatter();
bs.Serialize(fs, objectGraph);
}
}
public static T DeserializeFromBin(this FileInfo source)
{
if (!source.Exists)
{
return default(T);
}
using (var fs = source.OpenRead())
{
var bs = new BinaryFormatter();
return (T)bs.Deserialize(fs);
}
}
public static void SerializeToSoap(this object objectGraph, FileInfo target)
{
if (target.Exists)
{
target.Delete();
}
using (var fs = target.Create())
{
var bs = new SoapFormatter();
bs.Serialize(fs, objectGraph);
}
}
public static T DeserializeFromSoap(this FileInfo source)
{
if (!source.Exists)
{
return default(T);
}
using (var fs = source.OpenRead())
{
var bs = new SoapFormatter();
return (T)bs.Deserialize(fs);
}
}
댓글
댓글 쓰기