This is not my code I just have to understand it. The original programmer cannot be reached. dobj is just an object type. My main question is: Why does he deserialize again when dobj was never changed? Please ignore all his goto's for right now they are everywhere in this program.
////////////////////////
//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]");
Edit I added the rest of the method
Why does he deserialize again when dobj was never changed?
The object referenced by dobj
was changed. It is the same object no matter whether you refer to it via dobj
or dccmcaltered
:
dccmcaltered = dobj as ASM001.MatSettings;
This just gets a different typed reference to the same object;
dccmcaltered.ObjectLocation = wpuiobj.ObjectLocation;
dccmcaltered.ObjectOffset = wpuiobj.ObjectOffset;
dccmcaltered.UserDefinedLocation = wpuiobj.UserDefinedLocation;
dccmcaltered.Locked = wpuiobj.Locked;
And now: the values are changed.
Note that dccmcaltered
retains a reference to this original object, so those changes remain accessible even after dobj
is assigned a different object.