public static void fnSerializToFile(object v_object, string v_path)//将对象转换为文件
{
try
{
using (FileStream __fs = System.IO.File.Create(v_path))
{
BinaryFormatter __bf = new BinaryFormatter();
__bf.Serialize(__fs, v_object);
__fs.Close();
}
}
catch (Exception ex)
{
My.Msg.ExceptionInfo.ShowExceptionError("fnSerializ", ex);
}
} public static object fnDeSerializFromFile(string v_path)
{
try
{
using (FileStream __fs = System.IO.File.OpenRead(v_path))
{ byte[] byts = new byte[__fs.Length];
__fs.Read(byts, 0, (int)__fs.Length);
BinaryFormatter __bf = new BinaryFormatter();
object result = __bf.Deserialize(__fs);
__fs.Close();
return result;
}
}
catch (Exception ex)
{
My.Msg.ExceptionInfo.ShowExceptionError("fnDeSerializ", ex);
return null;
} }//从文件转换为对象
{
try
{
using (FileStream __fs = System.IO.File.Create(v_path))
{
BinaryFormatter __bf = new BinaryFormatter();
__bf.Serialize(__fs, v_object);
__fs.Close();
}
}
catch (Exception ex)
{
My.Msg.ExceptionInfo.ShowExceptionError("fnSerializ", ex);
}
} public static object fnDeSerializFromFile(string v_path)
{
try
{
using (FileStream __fs = System.IO.File.OpenRead(v_path))
{ byte[] byts = new byte[__fs.Length];
__fs.Read(byts, 0, (int)__fs.Length);
BinaryFormatter __bf = new BinaryFormatter();
object result = __bf.Deserialize(__fs);
__fs.Close();
return result;
}
}
catch (Exception ex)
{
My.Msg.ExceptionInfo.ShowExceptionError("fnDeSerializ", ex);
return null;
} }//从文件转换为对象
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货