【发布时间】:2014-10-13 18:27:45
【问题描述】:
这不是我的代码,我只需要理解它。无法联系到原始程序员。 dobj 只是一个对象类型。 我的主要问题是:为什么在 dobj 从未改变的情况下他又反序列化? 请忽略他所有的 goto,因为现在它们在这个程序中无处不在。
////////////////////////
//Deserialize Original//
////////////////////////
dobj = Generics.IO.BinarySerializer.Open(g_PathToTMP);
if (dobj == null)
{
///////
//LOG//
///////
goto Label_Done;
}
dccmcaltered = dobj as ASM001.MatSettings;
if (dccmcaltered == null)
goto Label_Done;
//
//////////////////////////////////////////
//Apply Changes To Deserialized Original//
//////////////////////////////////////////
dccmcaltered.ObjectLocation = wpuiobj.ObjectLocation;
dccmcaltered.ObjectOffset = wpuiobj.ObjectOffset;
dccmcaltered.UserDefinedLocation = wpuiobj.UserDefinedLocation;
dccmcaltered.Locked = wpuiobj.Locked;
dccmcaltered.RinseLocation = wpuiobj.RinseLocation;
dccmcaltered.RinseDepth = wpuiobj.RinseDepth;
dccmcaltered.DrainLocation = wpuiobj.DrainLocation;
dccmcaltered.DrainDepth = wpuiobj.DrainDepth;
//
////////////////////////
//Deserialize Original//Why did we need to Deserialize again
////////////////////////
dobj = Generics.IO.BinarySerializer.Open(g_PathToTMP);
if (dobj == null)
{
///////
//LOG//
///////
goto Label_Done;
}
dccmcoriginal = dobj as ASM001.MatSettings;
if (dccmcoriginal == null)
goto Label_Done;
//
bResult = Generics.IO.SerializerPlus.IsBinaryEqual(dccmcoriginal, dccmcaltered);
Label_Done:
;
bCurrent = bResult;
///////////
//Cleanup//
///////////
FileInfo fInfo = new FileInfo(g_PathToTMP);
if (fInfo.Exists)
fInfo.Delete();
//
System.Diagnostics.Debug.WriteLineIf(!bCurrent && g_bVerbose, "[Main] Mat is not Current [ASM = 1]!");
System.Diagnostics.Debug.WriteLineIf(bCurrent && g_bVerbose, "[Main] Mat is Current! [ASM = 0]");
编辑我添加了其余的方法
【问题讨论】:
-
天哪,为什么你/谁在使用
goto.... -
他被解雇了对吧?他第二次反序列化后的代码是否与原始工作流程完全相同?可以像复制粘贴问题一样简单。只是看起来像一个疏忽,没有真正的原因。任何答案都是纯粹的假设。
-
基本上,这是因为他是一个糟糕的程序员。那是不必要的代码,
goto只是加强了我的假设。 -
这应该直接转到codecrap.com
-
您的编辑清楚地表明他正在检查原始对象与更改后的对象。这就是两个反序列化调用的原因。
标签: c# serialization deserialization binary-serialization