コード例 #1
0
ファイル: LayerStack.cs プロジェクト: ikvm/bond
        private Error DeserializeLayerData(IBonded layerData, out TLayerData realLayerData)
        {
            Error error = null;

            if (layerData == null)
            {
                realLayerData = new TLayerData();
            }
            else
            {
                try
                {
                    realLayerData = layerData.Deserialize <TLayerData>();
                }
                catch (Exception ex)
                {
                    error = new Error
                    {
                        error_code = (int)ErrorCode.UnhandledLayerError
                    };

                    Log.Error(ex, "{0}.{1}: While unmarshaling layer data: {2}",
                              nameof(LayerStack <TLayerData>), nameof(DeserializeLayerData), ex.Message);

                    realLayerData = new TLayerData();
                }
            }

            return(error);
        }
コード例 #2
0
        // Deserialize T from IBonded<T> containing an instance or payload of derived class.
        void BondedDeserialize <T, D>()
            where T : class
            where D : class, T, new()
        {
            var from = Random.Init <D>();

            IBonded <T> bondedInstance   = new Bonded <D>(from);
            IBonded <T> bondedPayloadCB  = Util.MakeBondedCB(from);
            IBonded <T> bondedPayloadCB2 = Util.MakeBondedCB2(from);
            IBonded <T> bondedPayloadSP  = Util.MakeBondedSP(from);
            IBonded <BondClass <IBonded <T> > > nestedBonded =
                new Bonded <BondClass <IBonded <T> > >(new BondClass <IBonded <T> > {
                field = bondedInstance
            });

            for (var i = 2; --i != 0;)
            {
                var to1   = bondedInstance.Deserialize();
                var to2   = bondedPayloadCB.Deserialize();
                var toCb2 = bondedPayloadCB2.Deserialize();
                var to3   = bondedPayloadSP.Deserialize();

                Assert.IsTrue(to1.IsEqual <T>(from));
                Assert.IsTrue(to2.IsEqual <T>(from));
                Assert.IsTrue(toCb2.IsEqual <T>(from));
                Assert.IsTrue(to3.IsEqual <T>(from));
                Assert.IsTrue(nestedBonded.Deserialize().field.Deserialize().IsEqual(from));
            }
        }
コード例 #3
0
 /// <summary>
 /// Attempt to deserialize an object contained within a Bonded field as its derived type.
 /// </summary>
 /// <typeparam name="T">The base type of the Bonded field.</typeparam>
 /// <typeparam name="U">The desired derived type of the field.</typeparam>
 /// <param name="bonded">The Bonded source for the data.</param>
 /// <returns>Non-null object if the data was successfully desieralized, null otherwise.</returns>
 public static U TryDeserialize <T, U>(this IBonded <T> bonded)
     where U : class
 {
     try
     {
         return(bonded.Deserialize <U>());
     }
     catch (InvalidDataException)
     {
         return(null);
     }
 }
コード例 #4
0
        // Deserialize derived class from IBonded<T> containing an instance or payload of derived class.
        void BondedDowncastDeserialize <T, D>()
            where T : class
            where D : class, T, new()
        {
            var from = Random.Init <D>();

            IBonded <T> bondedInstance  = new Bonded <D>(from);
            IBonded <T> bondedPayloadCB = Util.MakeBondedCB(from);
            IBonded <T> bondedPayloadSP = Util.MakeBondedSP(from);

            for (var i = 2; --i != 0;)
            {
                var to1 = bondedInstance.Deserialize <D>();
                var to2 = bondedPayloadCB.Deserialize <D>();
                var to3 = bondedPayloadSP.Deserialize <D>();

                Assert.IsTrue(to1.IsEqual <D>(from));
                Assert.IsTrue(to2.IsEqual <D>(from));
                Assert.IsTrue(to3.IsEqual <D>(from));
            }
        }
コード例 #5
0
        private Error DeserializeLayerData(IBonded layerData, string uniqueId, out TLayerData realLayerData, Logger logger)
        {
            Error error = null;

            if (layerData == null)
            {
                realLayerData = new TLayerData();
            }
            else
            {
                try
                {
                    realLayerData = layerData.Deserialize <TLayerData>();
                }
                catch (Exception ex)
                {
                    logger.Site().Error(ex, "Unmarshaling layer data threw exception");
                    error         = Errors.MakeInternalServerError(ex, uniqueId, includeDetails: true);
                    realLayerData = new TLayerData();
                }
            }

            return(error);
        }
コード例 #6
0
 public T Deserialize()
 {
     return(bonded.Deserialize());
 }
コード例 #7
0
 public U Deserialize <U>()
 {
     return(_instance.Deserialize <U>());
 }