0

这不是我的代码,我只需要理解它。无法联系到原始程序员。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]");

编辑我添加了其余的方法

4

3 回答 3

4

当 dobj 从未更改时,为什么他再次反序列化?

所引用的对象dobj 更改。无论您通过dobj或引用它,它都是同一个对象dccmcaltered

dccmcaltered = dobj as ASM001.MatSettings;

这只是获得对同一对象的不同类型引用;

dccmcaltered.ObjectLocation = wpuiobj.ObjectLocation;
dccmcaltered.ObjectOffset = wpuiobj.ObjectOffset;
dccmcaltered.UserDefinedLocation = wpuiobj.UserDefinedLocation;
dccmcaltered.Locked = wpuiobj.Locked;

现在:值已更改。

请注意,dccmcaltered保留对该原始对象的引用,因此即使dobj分配了不同的对象,这些更改仍然可以访问。

于 2014-10-13T18:38:24.597 回答
2

稍后他想比较未更改的版本和更新的版本。首先,他反序列化为 dccmcaltered ,并设置一些属性。然后他在不设置这些属性的情况下反序列化为 dccmcoriginal。

很高兴我不必维护这个......祝你好运!

是的,比较是(aargh): bResult = Generics.IO.SerializerPlus.IsBinaryEqual(dccmcoriginal, dccmcaltered);

因此,您可以删除所有关于 dccmcoriginal 的内容,并在实际更改属性之前验证是否需要更改属性。

于 2014-10-13T18:37:38.840 回答
0

dobj因为他用这样的线条改变了第一个反序列化的对象,dccmcaltered.ObjectLocation = wpuiobj.ObjectLocation;所以他失去了“原始”dccmcaltered.ObjectLocation值并通过第二次反序列化“恢复”它们(到另一个对象中)......奇怪的家伙......欢呼

于 2014-10-13T18:39:05.470 回答